feat(frontend): implement center auth session flow with route guard

This commit is contained in:
root
2026-05-12 15:09:06 +00:00
parent 6219fbbcfe
commit d718128f89
12 changed files with 269 additions and 4 deletions

18
src/auth/auth-context.ts Normal file
View 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
}