30 lines
827 B
TypeScript
Executable File
30 lines
827 B
TypeScript
Executable File
// utils.ts
|
|
import { createDefine, type PageProps as FreshPageProps } from "fresh";
|
|
import type { SessionCookie } from "./routes/auth/callback.ts";
|
|
import type { User } from "./services/userService.ts";
|
|
|
|
export interface AuthState {
|
|
isAuthenticated: boolean;
|
|
userId: string | null;
|
|
userType: string | null;
|
|
roles: string[];
|
|
}
|
|
|
|
export interface State {
|
|
data: SessionCookie;
|
|
urlRoute: string;
|
|
host: string;
|
|
photoUrl: string;
|
|
stateId: string;
|
|
sealKey?: string; // The validated seal key for the current session
|
|
user?: User | null;
|
|
auth?: AuthState;
|
|
authError?: string;
|
|
/** Theme for initial HTML to avoid flash; set from cookie in middleware. */
|
|
themePreference?: "light" | "dark";
|
|
}
|
|
|
|
export type PageProps<Data = unknown> = FreshPageProps<Data, State>;
|
|
|
|
export const define = createDefine<State>();
|