Skip to main content
React hook to access authentication state and methods when using AuthProvider. Provides access to the current authentication state and functions to login, logout, and check auth status.

Signature

Returns

string | null
Error message if authentication failed, null otherwise
boolean
Whether the user is currently authenticated
boolean
Whether the initial authentication check has completed. Check this before rendering authenticated content to avoid flashing unauthenticated state.
() => Promise<void>
Initiates the login process. Redirects the user to the Tailor Platform authentication page.
() => Promise<void>
Logs out the current user. Clears authentication tokens and user session.
() => Promise<AuthState>
Checks the current authentication status. Makes a network request to verify auth status and attempts to refresh tokens internally if they are expired.

Usage

Basic Authentication Flow

Protected Content

Handling Authentication Errors

Manual Auth Status Check

Prerequisites

This hook must be used within an AuthProvider component:
If you use useAuth outside of an AuthProvider, it will throw an error: “useAuth/useAuthSuspense must be used within an AuthProvider”
  • Authentication - Complete authentication setup guide
  • AuthProvider - Authentication provider component
  • createAuthClient() - Create authentication client
  • useAuthSuspense() - Suspense-compatible authentication hook