Skip to Content
Getting StartedRoute Handler

Route Handler

Create a single catch-all route to handle all auth endpoints.

app/api/auth/[...authgear]/route.ts

This registers the following endpoints automatically:

EndpointMethodDescription
GET /api/auth/loginGETStarts the PKCE OAuth flow; redirects to Authgear
GET /api/auth/callbackGETHandles the OAuth callback; sets the session cookie
GET /api/auth/logoutGETClears the session cookie; redirects to Authgear logout
GET /api/auth/refreshGETManually refreshes the access token
GET /api/auth/userinfoGETReturns the current user as JSON (used by AuthgearProvider)

OAuth flow

Browser → GET /api/auth/login → 302 to Authgear (with PKCE code_challenge) → User authenticates → 302 back to /api/auth/callback?code=...&state=... → Token exchanged, session cookie set → 302 to postLoginRedirectURI (default: "/")
Last updated on