Skip to Content
UsageProtecting API Routes

Protecting API Routes

Use verifyAccessToken to validate a Bearer token in Route Handlers.

app/api/me/route.ts

verifyAccessToken fetches the JWKS from Authgear (cached for 1 hour), verifies the RS256 signature, and checks exp, iss, and aud.

JWTPayload fields

FieldTypeDescription
substringSubject (user ID)
issstringIssuer — your Authgear endpoint
audstring | string[]Audience — your client ID
expnumberExpiry (Unix timestamp)
iatnumberIssued at (Unix timestamp)
client_idstring?OAuth client ID
rolesstring[]?https://authgear.com/claims/user/roles
[key]unknownAny additional claims

Calling the API from a Server Action

When the proxy is active it injects the Authorization header for page requests, but not for direct fetch() calls. Use a Server Action to forward the session token:

app/dashboard/actions.ts
Last updated on