Skip to main content
Server TypeScript types used in logto-authkit server-side authentication and middleware.

Authentication Types

AuthPayload

JWT payload structure returned after token verification.
sub
string
required
Subject - the user ID from Logto
scope
string
required
OAuth scopes granted to the token
[key: string]
any
Additional claims from the JWT token

AuthContext

Authentication context attached to requests after verification.
userId
string | null
required
The authenticated user ID, or null if not authenticated
isAuthenticated
boolean
required
Whether the request has a valid authentication token
payload
AuthPayload | null
required
The full JWT payload if authenticated, otherwise null
isGuest
boolean
Whether the request is from a guest user (when allowGuest is enabled)
guestId
string
The guest user ID (when in guest mode)

VerifyAuthOptions

Configuration options for token verification.
logtoUrl
string
required
The Logto tenant URL (e.g., https://your-tenant.logto.app)
audience
string
required
The API resource identifier configured in Logto
Name of the cookie containing the JWT token
requiredScope
string
Required OAuth scope for authorization (e.g., "read:users")
allowGuest
boolean
default:false
Allow unauthenticated guest users with guest IDs

Express Types

ExpressRequest

Extended Express request interface with authentication context.
cookies
{ [key: string]: string }
Parsed cookies from the request
headers
{ [key: string]: string | string[] | undefined }
required
HTTP headers from the request
auth
AuthContext
Authentication context added by the middleware

ExpressResponse

Express response interface for middleware.
status
(code: number) => ExpressResponse
required
Set HTTP status code
json
(obj: any) => ExpressResponse
required
Send JSON response

ExpressNext

Express next function type.

Next.js Types

NextRequest

Next.js request interface for route handlers and middleware.
cookies
{ get: (name: string) => { value: string } | undefined }
required
Cookie accessor for Next.js requests
headers
{ get: (name: string) => string | null }
required
Header accessor for Next.js requests

NextResponse

Next.js response interface for route handlers.
json
(body: any, init?: { status?: number }) => NextResponse
required
Send JSON response with optional status code

Usage Examples

Express Middleware

Next.js Route Handler

Guest Mode