HandleAuthOptions type configures the handleAuth callback route handler that processes authentication responses from WorkOS.
Type definition
Properties
The pathname to redirect users to after successful authentication. This can include query parameters.If a
returnPathname was specified in the authorization URL state, it will override this value.The base URL for your application. Useful when running in containerized environments (like Docker) where the request hostname may differ from the actual application URL.If provided, must be a valid URL (e.g.,
https://example.com).Callback function invoked after successful authentication, before redirecting the user. Use this to perform custom actions like logging, analytics, or database updates.Receives HandleAuthSuccessData containing the session and authentication details.
Custom error handler for authentication failures. If not provided, displays a default error page.Must return a
Response object to send to the user.HandleAuthSuccessData
The data passed to theonSuccess callback extends Session with additional authentication metadata:
OAuth tokens if the authentication was performed via an OAuth provider (e.g., Google, Microsoft).
The ID of the organization the user authenticated with, if applicable.
The method used for authentication (e.g.,
"Password", "GoogleOAuth", "MagicLink").Custom state data that was passed to the authorization URL, if any.
Usage
Basic configuration
With success callback
With custom error handling
With baseURL for Docker
Related functions
handleAuth()- Creates the authentication callback handler (see source at ~/workspace/source/src/authkit-callback-route.ts:44)