Fixed partial handling and added cookies

This commit is contained in:
Kevin FEDYNA
2025-01-21 16:09:36 +01:00
parent b364f6cbab
commit fa66621abc
12 changed files with 158 additions and 48 deletions
+7 -2
View File
@@ -1,7 +1,7 @@
import { FreshContext } from "$fresh/server.ts";
import { getCookies } from "$std/http/cookie.ts";
import { getJwtPayload, isJwtValid } from "@popov/jwt";
import { LoginJWT } from "$root/routes/login.tsx";
import { CasContent, LoginJWT } from "$root/defaults/interfaces.ts";
const PUBLIC_ROUTES = [
"/",
@@ -16,6 +16,7 @@ const jwtKeyCache: Record<string, string> = {};
export interface State {
isAuthenticated: boolean;
session: CasContent;
}
function isRoutePublic(route: string) {
@@ -44,12 +45,16 @@ export const handler = [
}
const content = getJwtPayload(cookies["sessionToken"]) as LoginJWT;
const key = getKey(content.user.uid as string);
const key = getKey(content.user.uid);
context.state.isAuthenticated = await isJwtValid(
cookies["sessionToken"],
key,
);
const session: CasContent =
(getJwtPayload(cookies["sessionToken"]) as LoginJWT).user;
context.state.session = session;
return await context.next();
},