krishna_sales/src/auth/context.ts
2026-07-30 10:36:58 +05:30

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;
}