35 lines
961 B
TypeScript
35 lines
961 B
TypeScript
/**
|
|
* Declares the session's React context. `AuthProvider` fills it and `useAuth`
|
|
* reads it; nothing else should touch it.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
import { createContext, type Dispatch, type SetStateAction } from "react";
|
|
|
|
import type { Session } from "../../utils/auth/storage.ts";
|
|
|
|
/**
|
|
* Provided by `AuthProvider` to `useAuth`, which builds the session's API on
|
|
* it.
|
|
*/
|
|
export interface AuthContextValue {
|
|
authResponse: Session | null;
|
|
/**
|
|
* Replaces the session in memory only. Its callers store the new session
|
|
* themselves, with `storeSession`, so other tabs follow.
|
|
*/
|
|
setAuthResponse: Dispatch<SetStateAction<Session | null>>;
|
|
}
|
|
|
|
/**
|
|
* The session's context. Its default, a signed-out session whose setter does
|
|
* nothing, is only seen outside `AuthProvider`, as in some tests.
|
|
*/
|
|
export const AuthContext: React.Context<AuthContextValue> = createContext<
|
|
AuthContextValue
|
|
>({
|
|
authResponse: null,
|
|
setAuthResponse: () => {},
|
|
});
|