import { createContext } from "react"; import type { Department, Factor, Me, PresenceUser } from "./types"; export type AuthStatus = "loading" | "anonymous" | "ready" | "locked"; export interface AuthState { status: AuthStatus; /** Null while loading, when signed out, and when a 423 arrived before /me answered. */ me: Me | null; departments: Department[]; /** Shown on the sign-in page once, for example after a session ended. */ notice: string | null; presence: PresenceUser[]; refresh: () => Promise; signInPassword: (login: string, password: string) => Promise; signInPin: (empNo: string, pin: string) => Promise; signOut: () => Promise; /** Drops the session in the browser without calling the server, with a notice for the sign-in page. */ endSession: (notice: string | null) => void; unlock: (factor: Factor, secret: string) => Promise; lock: () => Promise; /** Replaces the cached Me, for example after a PIN change. */ setMe: (me: Me) => void; roleLabel: (role: string) => string; } export const AuthCtx = createContext(null);