Started documenting code
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { Partial } from "$fresh/runtime.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
import { State } from "$root/defaults/interfaces.ts";
|
||||
import { AppProperties } from "$root/defaults/interfaces.ts";
|
||||
import Navbar from "$root/routes/(_islands)/Navbar.tsx";
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
import { State } from "$root/defaults/interfaces.ts";
|
||||
import Header from "$root/routes/(_components)/Header.tsx";
|
||||
import Footer from "$root/routes/(_components)/Footer.tsx";
|
||||
|
||||
|
||||
+16
-8
@@ -1,7 +1,7 @@
|
||||
import { FreshContext } from "$fresh/server.ts";
|
||||
import { getCookies } from "$std/http/cookie.ts";
|
||||
import { getJwtPayload, isJwtValid } from "@popov/jwt";
|
||||
import { CasContent, LoginJWT } from "$root/defaults/interfaces.ts";
|
||||
import { CasContent, LoginJWT, State } from "$root/defaults/interfaces.ts";
|
||||
|
||||
const PUBLIC_ROUTES = [
|
||||
"/",
|
||||
@@ -13,21 +13,29 @@ const PUBLIC_ROUTES = [
|
||||
];
|
||||
|
||||
const jwtKeyCache: Record<string, string> = {};
|
||||
const deleteKey = (user: string) => delete jwtKeyCache[user];
|
||||
|
||||
export interface State {
|
||||
isAuthenticated: boolean;
|
||||
session: CasContent;
|
||||
}
|
||||
|
||||
function isRoutePublic(route: string) {
|
||||
return PUBLIC_ROUTES.includes(route) || route.match(/\..+$/);
|
||||
/**
|
||||
* Checks if the given route is public.
|
||||
* @param route The route to check.
|
||||
* @returns `true` if the route is public, `false` otherwise.
|
||||
*/
|
||||
function isRoutePublic(route: string): boolean {
|
||||
return PUBLIC_ROUTES.includes(route) ||
|
||||
!!(route.match(/\..+$/)?.[0] ?? false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the given user's key, creating it if not already existing.
|
||||
* @param user The key's user.
|
||||
* @returns The user's key.
|
||||
*/
|
||||
export function getKey(user: string): string {
|
||||
if (!jwtKeyCache[user]) {
|
||||
const keyBuffer = new Uint8Array(32);
|
||||
crypto.getRandomValues(keyBuffer);
|
||||
jwtKeyCache[user] = new TextDecoder().decode(keyBuffer);
|
||||
setTimeout(deleteKey, 0x75300, user);
|
||||
}
|
||||
|
||||
return jwtKeyCache[user];
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
import { State } from "$root/defaults/interfaces.ts";
|
||||
import { parse, type RegularTagNode } from "@melvdouc/xml-parser";
|
||||
import {
|
||||
CasContent,
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { State } from "$root/routes/_middleware.ts";
|
||||
import { State } from "$root/defaults/interfaces.ts";
|
||||
import { deleteCookie } from "$std/http/cookie.ts";
|
||||
|
||||
const CAS = "https://ident.univ-amu.fr/cas";
|
||||
|
||||
Reference in New Issue
Block a user