Skip to content

Auth Hooks

All auth hooks use TanStack Query mutations/queries for automatic loading states and error handling.

const { mutate, isPending } = useLogin();
mutate({ email: 'admin@example.com', password: 'secret' });
const { mutate } = useLogout();
mutate(); // Redirects to /login
const query = useGetIdentity();
// query.data → { id: '1', name: 'Admin', avatar: '...' } | null
const { isAuthenticated, isLoading } = useIsAuthenticated();
const { raw, has, can, isLoading, refetch } = usePermissions<string[]>();
// Check specific permission
if (has('admin')) { /* ... */ }
// Check resource:action permission
if (can('posts', 'edit')) { /* ... */ }
// Session-level refresh (e.g. after role upgrade)
await refetch();
const { mutate } = useOnError();
mutate(error); // Calls authProvider.onError → may logout or redirect

useRegister(), useForgotPassword(), useUpdatePassword()

Section titled “useRegister(), useForgotPassword(), useUpdatePassword()”

Same mutation pattern as useLogin().