refactor(frontend): create centralised auth manager (#24)
- Resolves #17 Reviewed-on: #24
This commit was merged in pull request #24.
This commit is contained in:
20
frontend/src/auth/AuthContext.ts
Normal file
20
frontend/src/auth/AuthContext.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { createContext } from "react";
|
||||
import type { User } from "../utils/types.ts";
|
||||
|
||||
type AuthContextValue = {
|
||||
/** The currently authenticated user, or null when logged out. */
|
||||
user: User | null;
|
||||
/** True until the initial "who am I" request has resolved. */
|
||||
loading: boolean;
|
||||
/** Exchange a Google credential for a session, then load the user. */
|
||||
login: (googleCredential: string) => Promise<void>;
|
||||
/** End the session and clear the user. */
|
||||
logout: () => Promise<void>;
|
||||
/** Re-fetch the current user (e.g. after a profile change). */
|
||||
refresh: () => Promise<void>;
|
||||
};
|
||||
|
||||
const AuthContext = createContext<AuthContextValue | null>(null);
|
||||
|
||||
export { AuthContext };
|
||||
export type { AuthContextValue };
|
||||
Reference in New Issue
Block a user