19 lines
491 B
TypeScript
19 lines
491 B
TypeScript
import { createContext, useContext } from 'react';
|
|
|
|
export interface AuthValue {
|
|
authed: boolean;
|
|
isAdmin: boolean;
|
|
roles: string[];
|
|
userEmail: string | null;
|
|
login: (email: string, password: string, orgId?: string) => Promise<void>;
|
|
logout: () => void;
|
|
}
|
|
|
|
export const AuthCtx = createContext<AuthValue | null>(null);
|
|
|
|
export function useAuth(): AuthValue {
|
|
const v = useContext(AuthCtx);
|
|
if (!v) throw new Error('useAuth must be used within <AuthProvider>');
|
|
return v;
|
|
}
|