Check if user is allowed to access

This commit is contained in:
2026-01-06 10:32:52 +01:00
parent 5856eea5f3
commit cb89a45743
+10 -5
View File
@@ -21,8 +21,9 @@ const deleteKey = (user: string) => delete jwtKeyCache[user];
* @returns `true` if the route is public, `false` otherwise. * @returns `true` if the route is public, `false` otherwise.
*/ */
function isRoutePublic(route: string): boolean { function isRoutePublic(route: string): boolean {
return PUBLIC_ROUTES.includes(route) || return (
!!(route.match(/\..+$/)?.[0] ?? false); PUBLIC_ROUTES.includes(route) || !!(route.match(/\..+$/)?.[0] ?? false)
);
} }
/** /**
@@ -67,9 +68,13 @@ export const handler: MiddlewareHandler<State>[] = [
); );
if (context.state.isAuthenticated) { if (context.state.isAuthenticated) {
const session: CasContent = const session: CasContent = (
(getJwtPayload(cookies["sessionToken"]) as LoginJWT).user; getJwtPayload(cookies["sessionToken"]) as LoginJWT
context.state.session = session; ).user;
if (session.memberOf.includes("cn=amu:ufr:polytech:ldap")) {
console.log("Polytech trouvé !");
context.state.session = session;
}
} }
return await context.next(); return await context.next();