Boilerplate generator and deno tasks for monorepo

This commit is contained in:
Emma
2023-05-01 20:28:18 -06:00
parent a367562ba0
commit a910783882
36 changed files with 1164 additions and 47 deletions

10
middleware/auth.ts Normal file
View File

@@ -0,0 +1,10 @@
import { Context } from "oak";
import { USER_TOKEN } from "../constsAndEnums.ts";
import { verifyUserSessionToken } from "../lib/jwt.ts";
export const authenticateUser = async (ctx: Context, next: () => any) => {
const jwt = await ctx.cookies.get(USER_TOKEN);
if (!jwt) return next();
ctx.state.user = await verifyUserSessionToken(jwt);
await next();
}

10
middleware/bodyExists.ts Normal file
View File

@@ -0,0 +1,10 @@
import { Middleware } from "oak"
export const bodyExists: Middleware = async (ctx, next) => {
if (ctx.request.hasBody) await next();
else {
ctx.response.status = 400;
ctx.response.body = 'Body not provided to endpoint that requires it';
}
}

0
middleware/index.ts Normal file
View File