2023-05-04 20:04:06 -06:00

11 lines
366 B
TypeScript

import { Context } from "oak";
import { USER_TOKEN } from "common/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();
}