Check if user is allowed to access
This commit is contained in:
@@ -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,10 +68,14 @@ 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
|
||||||
|
).user;
|
||||||
|
if (session.memberOf.includes("cn=amu:ufr:polytech:ldap")) {
|
||||||
|
console.log("Polytech trouvé !");
|
||||||
context.state.session = session;
|
context.state.session = session;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return await context.next();
|
return await context.next();
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user