useAuth Hook
The useAuth hook provides access to authentication state and actions from any component within the AuthProvider.
Basic Usage#
TSX
Loading...
Return Values#
user#
The current user object, or null if not authenticated.
TSX
Loading...
isAuthenticated#
Boolean indicating if user is authenticated (non-guest).
TSX
Loading...
isGuest#
Boolean indicating if current session is a guest.
TSX
Loading...
isLoading#
Boolean indicating if auth state is being fetched.
TSX
Loading...
error#
Error object if authentication failed.
TSX
Loading...
login#
Function to trigger login redirect or modal.
TSX
Loading...
logout#
Function to log out the user.
TSX
Loading...
mutate#
SWR mutate function to manually revalidate auth state.
TSX
Loading...
loginWithCredentials#
Function to log in with email/password.
TSX
Loading...
Examples#
Navigation with Auth State#
TSX
Loading...
Protected Component#
TSX
Loading...
Role-Based Access#
TSX
Loading...
Guest Upgrade Prompt#
TSX
Loading...
Login Form#
TSX
Loading...
Logout with Confirmation#
TSX
Loading...
TypeScript#
Custom User Type#
TSX
Loading...
Full Return Type#
TypeScript
Loading...
Requirements#
The useAuth hook must be used within an AuthProvider:
TSX
Loading...