import { createContext, use } from "react"; import type { paths } from "@/shared/api"; type AuthContextValue = { login: (email: string, password: string) => Promise; logout: () => Promise; ready: boolean; register: (email: string, password: string) => Promise; retry: () => void; signedOut: boolean; /** Refresh failed with a network error or 5xx; the refresh cookie may still be valid. */ unavailable: boolean; user: undefined | User; }; type User = paths["/api/v1/auth/me"]["get"]["responses"][200]["content"]["application/json"]; const AuthContext = createContext(undefined); function useAuth() { const context = use(AuthContext); if (!context) throw new Error("AuthProvider is required"); return context; } export { AuthContext, useAuth, type User };