Overview
TheAuthProvider component is the root authentication provider that wraps your application and provides authentication context to all child components. It integrates with Logto’s authentication service and manages user session state.
Props
The child components to be wrapped by the authentication provider.
Logto configuration object containing your application credentials and settings.
The URL to redirect to after successful authentication. Defaults to the current page URL if not specified.
Custom navigation function to handle routing in your application. Useful for integration with client-side routers like Next.js or React Router.
Enable popup-based sign-in flow instead of full-page redirect. When enabled, the sign-in page opens in a popup window.
Usage
Basic Setup
With Callback URL
With Popup Sign-In
With Custom Navigation (Next.js)
Features
- Client-Side Only: Automatically prevents SSR issues by rendering only on the client side
- Cross-Tab Synchronization: Auth state is synchronized across browser tabs and windows
- Auto Token Management: Automatically manages JWT tokens in cookies
- Error Handling: Built-in error recovery and automatic logout on auth failures
- Popup Support: Optional popup-based authentication flow
- Rate Limiting: Prevents excessive auth state refresh calls
Notes
- The
AuthProvidermust be placed at the root of your component tree, above any components that use authentication - Configuration is validated on mount to ensure all required fields are present
- Auth state changes trigger a custom
auth-state-changedevent on the window object - The provider automatically handles token refresh and session management