import { createContext, useContext } from 'react' import type { SessionPrincipal } from './auth' // AuthState is the shape the provider exposes. It lives here, alongside the context object and the // useAuth hook, so the provider file (AuthContext.tsx) only exports a component and stays inside the // React Fast Refresh boundary. export interface AuthState { principal: SessionPrincipal | null loading: boolean refresh: () => Promise logout: () => Promise } export const AuthContext = createContext(null) export function useAuth(): AuthState { const ctx = useContext(AuthContext) if (!ctx) { throw new Error('useAuth must be used within AuthProvider') } return ctx }