feat(frontend): implement center auth session flow with route guard
This commit is contained in:
18
src/auth/auth-context.ts
Normal file
18
src/auth/auth-context.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user