dc0af96470
The AuthenticatedState interface was updated to directly store the `displayName` and `uid` properties. Previously, it stored the entire `CasContent` object, which contained these properties along with others that were not consistently used. This change simplifies the interface and reduces redundancy.
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { FreshContext, MiddlewareHandler } from "$fresh/server.ts";
|
|
import {
|
|
AppProperties,
|
|
AuthenticatedState,
|
|
} from "$root/defaults/interfaces.ts";
|
|
|
|
export const handler: MiddlewareHandler<AuthenticatedState>[] = [
|
|
/**
|
|
* Get all available pages for current user.
|
|
* @param request The HTTP incomming request.
|
|
* @param context The Fresh context object with custom `AuthenticatedState`.
|
|
* @returns The response from the next middleware.
|
|
*/
|
|
async function getAllAvailablePages(
|
|
request: Request,
|
|
context: FreshContext<AuthenticatedState>,
|
|
): Promise<Response> {
|
|
const pathname = new URL(request.url).pathname;
|
|
const currentApp = pathname.split("/")[1];
|
|
const properties: AppProperties = (await import(
|
|
`./${currentApp}/(_props)/props.ts`
|
|
)).default;
|
|
|
|
context.state.availablePages = properties.pages;
|
|
if (
|
|
context.state.role == "etudiant" &&
|
|
Deno.env.get("LOCAL") != "true"
|
|
) {
|
|
properties.adminOnly.forEach((page) =>
|
|
delete context.state.availablePages[page]
|
|
);
|
|
}
|
|
|
|
return await context.next();
|
|
},
|
|
];
|