Move auth and timezone hooks into dedicated hook files

This commit is contained in:
2026-04-18 20:35:28 +02:00
parent d9550ae4aa
commit fba7675eb8
8 changed files with 40 additions and 49 deletions

View File

@@ -10,7 +10,6 @@
import {
createContext,
useCallback,
useContext,
useMemo,
useState,
} from "react";
@@ -25,7 +24,7 @@ interface AuthState {
expiresAt: string | null;
}
interface AuthContextValue {
export interface AuthContextValue {
/** `true` when a valid session token is held in state. */
isAuthenticated: boolean;
/**
@@ -41,7 +40,7 @@ interface AuthContextValue {
// Context
// ---------------------------------------------------------------------------
const AuthContext = createContext<AuthContextValue | null>(null);
export const AuthContext = createContext<AuthContextValue | null>(null);
const SESSION_KEY = "bangui_token";
const SESSION_EXPIRES_KEY = "bangui_expires_at";
@@ -97,22 +96,3 @@ export function AuthProvider({
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
}
// ---------------------------------------------------------------------------
// Hook
// ---------------------------------------------------------------------------
/**
* Access authentication state and actions.
*
* Must be called inside a component rendered within `<AuthProvider>`.
*
* @throws {Error} When called outside of `<AuthProvider>`.
*/
export function useAuth(): AuthContextValue {
const ctx = useContext(AuthContext);
if (ctx === null) {
throw new Error("useAuth must be used within <AuthProvider>.");
}
return ctx;
}