Skip to main content

Overview

The verifyNextAuth function is designed specifically for Next.js App Router, providing authentication verification for middleware and API routes with Next.js-specific request handling.

Signature

Parameters

request
NextRequest
required
Next.js request object from middleware or API routes
options
VerifyAuthOptions
required
Configuration options for token verification

Returns

result
Promise<VerifyAuthResult>
Promise that resolves to a result object indicating success or failureSuccess Response:Failure Response:

AuthContext Properties

Examples

Middleware Protection

API Route Protection

With Guest Support

Middleware with Guest Support

Role-Based Access Control

Custom Error Handling

Extracting User Info in Server Component

Token Extraction Order

The function extracts tokens in this order:
  1. Cookie (using cookieName option, defaults to logto_authtoken)
  2. Authorization header (Bearer token)

Response Patterns

Authenticated User

Guest User (when allowGuest: true)

Failed Authentication (when allowGuest: false)

See Also