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();

usePermissions() is a client-side rendering helper. It can hide or disable UI, but APIs, data providers, and database policies must enforce authorization independently.

const permissionHints = usePermissions<string[]>();
// Change navigation or a disabled control from a UI hint.
if (permissionHints.has('admin')) { /* ... */ }
// Read a UI hint using the resource:action naming convention.
if (permissionHints.can('posts', 'edit')) { /* ... */ }
await permissionHints.refetch();

The built-in Supabase and SSO providers expose getPermissions(), but it returns null until the application configures a trusted resolver. Resolver values are UI hints only; do not use these browser-visible values as an API, RLS, or action authorization decision. The backend must authenticate and authorize every request.

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().