19 lines
559 B
TypeScript
19 lines
559 B
TypeScript
import { createContext, useContext } from 'react'
|
|
import type { AuthSession } from '../lib/auth-storage'
|
|
|
|
export type AuthContextValue = {
|
|
session: AuthSession | null
|
|
isAuthed: boolean
|
|
login: (email: string, password: string) => Promise<void>
|
|
logout: () => Promise<void>
|
|
ensureFreshToken: () => Promise<string | null>
|
|
}
|
|
|
|
export const AuthContext = createContext<AuthContextValue | null>(null)
|
|
|
|
export function useAuth() {
|
|
const ctx = useContext(AuthContext)
|
|
if (!ctx) throw new Error('useAuth must be used inside <AuthProvider>')
|
|
return ctx
|
|
}
|