Files
frontend/src/features/auth/model/auth-context.ts
T
codex-bot 3af9df0ae2
Frontend verify / commits (push) Skipped
Frontend verify / security (push) Successful in 1m3s
Frontend verify / verify (push) Failing after 7m11s
fix: keep session when refresh fails on network error or 5xx (WealthLedger/frontend#97)
2026-10-23 15:06:20 +03:00

32 lines
825 B
TypeScript

import { createContext, use } from "react";
import type { paths } from "@/shared/api";
type AuthContextValue = {
login: (email: string, password: string) => Promise<void>;
logout: () => Promise<void>;
ready: boolean;
register: (email: string, password: string) => Promise<void>;
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<AuthContextValue | undefined>(undefined);
function useAuth() {
const context = use(AuthContext);
if (!context) throw new Error("AuthProvider is required");
return context;
}
export { AuthContext, useAuth, type User };