Overview
TheCallbackPage component handles the OAuth callback flow after a user completes authentication with Logto. It processes the authorization code, exchanges it for tokens, and redirects the user appropriately.
Props
Additional CSS classes to apply to the container element.
Custom component to display while the callback is being processed. If not provided, a default loading spinner with “Signing you in…” text is shown.
Custom component to display after successful authentication. If not provided, a default spinner with “Authentication complete! Redirecting…” text is shown.
Callback function that is called after successful authentication, before any redirect or window close actions.
Callback function that is called if an error occurs during the authentication callback.
Usage
Basic Setup
Create a callback route in your application (e.g.,/callback or /auth/callback):
With Custom Loading Component
With Callbacks
Fully Customized
Behavior
Standard Flow
- User is redirected to this page after authenticating with Logto
- The component exchanges the authorization code for tokens
onSuccesscallback is called (if provided)- User is redirected to the home page (
/)
Popup Flow
When authentication happens in a popup window:- Component detects it’s running in a popup (via
window.openerorsessionStorage) - Exchanges authorization code for tokens
onSuccesscallback is called (if provided)- Sends
SIGNIN_SUCCESSmessage to parent window viapostMessage - Falls back to
localStorageifpostMessagefails - Closes the popup window after a 100ms delay
Error Handling
If an error occurs during the callback:- Error is logged to console
onErrorcallback is called (if provided)- Loading state continues (manual error handling required)
Notes
- The component must be used within an
AuthProvidercontext - The callback URL must be registered in your Logto application settings
- The component handles both full-page redirects and popup authentication flows automatically
- A
simple_logto_popup_flowsessionStorage flag persists the popup state across redirects - The component prevents duplicate callback execution using a ref
- Spin animation keyframes are injected into the document head automatically
Related
- SignInPage - Initiates the sign-in flow
- AuthProvider - Required context provider