Refactor AuthenticatedState to store displayName and uid
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.
This commit is contained in:
@@ -5,7 +5,8 @@ export interface AuthenticatedState {
|
|||||||
isAuthenticated: true;
|
isAuthenticated: true;
|
||||||
isFromPolytech: boolean;
|
isFromPolytech: boolean;
|
||||||
role: "etudiant" | "professeur" | "administration" | "autre";
|
role: "etudiant" | "professeur" | "administration" | "autre";
|
||||||
session: CasContent;
|
displayName: string;
|
||||||
|
uid: string;
|
||||||
availablePages: Record<string, string>;
|
availablePages: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const handler: MiddlewareHandler<AuthenticatedState>[] = [
|
|||||||
|
|
||||||
context.state.availablePages = properties.pages;
|
context.state.availablePages = properties.pages;
|
||||||
if (
|
if (
|
||||||
context.state.session.eduPersonPrimaryAffiliation == "student" &&
|
context.state.role == "etudiant" &&
|
||||||
Deno.env.get("LOCAL") != "true"
|
Deno.env.get("LOCAL") != "true"
|
||||||
) {
|
) {
|
||||||
properties.adminOnly.forEach((page) =>
|
properties.adminOnly.forEach((page) =>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
export async function Index(_request: Request, context: FreshContext<State>) {
|
export async function Index(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function Courses(_request: Request, context: FreshContext<State>) {
|
async function Courses(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
export async function Index(_request: Request, context: FreshContext<State>) {
|
export async function Index(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { State } from "$root/routes/_middleware.ts";
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
async function Notes(_request: Request, context: FreshContext<State>) {
|
async function Notes(_request: Request, context: FreshContext<State>) {
|
||||||
return <h2>Welcome to {context.state.session?.displayName}.</h2>;
|
return <h2>Welcome to {context.state.displayName || 'Guest'}.</h2>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -92,9 +92,9 @@ export const handler: Handlers<null, AuthenticatedState> = {
|
|||||||
using connection = connect("students");
|
using connection = connect("students");
|
||||||
const database = connection.database;
|
const database = connection.database;
|
||||||
|
|
||||||
if (context.state.session.eduPersonPrimaryAffiliation == "student") {
|
if (context.state.role == "etudiant") {
|
||||||
return new Response(
|
return new Response(
|
||||||
JSON.stringify(getItself(database, context.state.session.uid)),
|
JSON.stringify(getItself(database, context.state.uid)),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
|||||||
@@ -8,13 +8,7 @@ import SelfPortrait from "$root/routes/(apps)/students/(_components)/SelfPortrai
|
|||||||
|
|
||||||
// deno-lint-ignore require-await
|
// deno-lint-ignore require-await
|
||||||
export async function Index(_request: Request, context: FreshContext<State>) {
|
export async function Index(_request: Request, context: FreshContext<State>) {
|
||||||
return (
|
return <h2>Welcome {context.state.displayName || 'Guest'}!</h2>;
|
||||||
<>
|
|
||||||
<h2>Welcome {context.state.session?.givenName}!</h2>
|
|
||||||
<h3>Your amU identity</h3>
|
|
||||||
<SelfPortrait self={context.state.session!} />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const config = getPartialsConfig();
|
export const config = getPartialsConfig();
|
||||||
|
|||||||
@@ -77,13 +77,14 @@ export const handler: MiddlewareHandler<State>[] = [
|
|||||||
context.state.isFromPolytech = isFromPolytech;
|
context.state.isFromPolytech = isFromPolytech;
|
||||||
|
|
||||||
if (isFromPolytech) {
|
if (isFromPolytech) {
|
||||||
context.state.session = session;
|
context.state.displayName = session.displayName;
|
||||||
|
context.state.uid = session.uid;
|
||||||
|
|
||||||
if (session.eduPersonPrimaryAffiliation.includes("faculty")) {
|
if (session.eduPersonPrimaryAffiliation == "faculty") {
|
||||||
context.state.role = "professeur"
|
context.state.role = "professeur"
|
||||||
} else if (session.eduPersonPrimaryAffiliation.includes("employee")) {
|
} else if (session.eduPersonPrimaryAffiliation == "employee") {
|
||||||
context.state.role = "administration"
|
context.state.role = "administration"
|
||||||
} else if (session.eduPersonPrimaryAffiliation.includes("student")) {
|
} else if (session.eduPersonPrimaryAffiliation == "student") {
|
||||||
context.state.role = "etudiant";
|
context.state.role = "etudiant";
|
||||||
} else {
|
} else {
|
||||||
context.state.role = "autre";
|
context.state.role = "autre";
|
||||||
|
|||||||
Reference in New Issue
Block a user