Overview
Autumn’s backend integration creates API routes that proxy requests to the Autumn API while injecting customer identity from your auth system. This ensures customers can only access their own data.Framework Adapters
Next.js
For Next.js App Router, use theautumn-js/next adapter:
Handler Options
(request: Request) => AuthResult
required
Function to extract customer identity from the request. Must return an object with
customerId or null for unauthenticated requests.string
Autumn API secret key. Defaults to
AUTUMN_SECRET_KEY environment variable.string
Autumn API base URL. Defaults to
https://api.useautumn.com/v1.string
default:"/api/autumn"
Path prefix for routes. Must match the route file location.
Hono
For Hono applications, use theautumn-js/hono adapter:
Handler Options
(c: Context) => AuthResult
required
Function to extract customer identity from the Hono context.
string
Autumn API secret key.
string
Autumn API base URL.
string
default:"/api/autumn"
Path prefix for routes.
Framework-Agnostic
For custom frameworks, use the genericautumnHandler:
Handler Options
object
required
Request object with
url, method, and body.string
Customer ID to inject into the request.
CustomerData
Additional customer data (email, name, etc.).
object
Client configuration with
secretKey and optional baseURL.string
default:"/api/autumn"
Path prefix for routes.
RouteDefinition[]
Custom route definitions (for advanced use cases).
Identity Resolution
Theidentify function is called for every request and must return customer identity:
Return Type
Examples
Basic User ID
With Customer Data
Organization-Based
User + Organization Composite
Better Auth Plugin
If you’re using Better Auth, the Autumn plugin simplifies setup:Customer Scope
'user' | 'organization' | 'user_and_organization'
default:"user"
Determines how customer identity is resolved:
user- Customer ID is the user’s IDorganization- Customer ID is the active organization’s IDuser_and_organization- Customer ID combines both (format:user_{userId}_org_{orgId})
Custom Identity Function
Override the default behavior with a customidentify function:
Identify Function Parameters
BetterAuthSession | null
Better Auth session object with user and session data.
BetterAuthOrganization | null
Active organization object (if using Better Auth organizations).
Advanced: Custom Routes
For advanced use cases, define custom routes:Available Route Configs
getOrCreateCustomerattachpreviewAttachupdateSubscriptionpreviewUpdateSubscriptionmultiAttachpreviewMultiAttachsetupPaymentopenCustomerPortalcreateReferralCoderedeemReferralCodelistPlanslistEventsaggregateEvents
Core Handler
For maximum flexibility, use the core handler directly:Core Handler Options
(raw: unknown) => AuthResult
required
Function to extract customer identity. Receives the raw request object.
string
Autumn API secret key.
string
Autumn API base URL.
string
default:"/api/autumn"
Path prefix for routes.
RouteDefinition[]
Custom route definitions.
Core Handler Request
string
required
HTTP method (
GET, POST, DELETE).string
required
Request path (e.g.,
/api/autumn/attach).unknown
Request body (parsed JSON).
unknown
Original framework request object (passed to
identify).