Auth Hooks
All auth hooks use TanStack Query mutations/queries for automatic loading states and error handling.
Hooks Reference
Section titled “Hooks Reference”useLogin()
Section titled “useLogin()”const { mutate, isPending } = useLogin();mutate({ email: 'admin@example.com', password: 'secret' });useLogout()
Section titled “useLogout()”const { mutate } = useLogout();mutate(); // Redirects to /loginuseGetIdentity()
Section titled “useGetIdentity()”const query = useGetIdentity();// query.data → { id: '1', name: 'Admin', avatar: '...' } | nulluseIsAuthenticated()
Section titled “useIsAuthenticated()”const { isAuthenticated, isLoading } = useIsAuthenticated();usePermissions<T>()
Section titled “usePermissions<T>()”const { raw, has, can, isLoading, refetch } = usePermissions<string[]>();
// Check specific permissionif (has('admin')) { /* ... */ }
// Check resource:action permissionif (can('posts', 'edit')) { /* ... */ }
// Session-level refresh (e.g. after role upgrade)await refetch();useOnError()
Section titled “useOnError()”const { mutate } = useOnError();mutate(error); // Calls authProvider.onError → may logout or redirectuseRegister(), useForgotPassword(), useUpdatePassword()
Section titled “useRegister(), useForgotPassword(), useUpdatePassword()”Same mutation pattern as useLogin().