- an app in the Developer Area with the On-platform type available on your account (Choose your app type)
- a Next.js App Router project with React 18 or later, served over
httpswith a browser-trusted certificate - a domain you control, if you configure the app through an App Manifest
Register your app
1
Create the app and save its credentials
In the Developer Area, click Create app. The dialog that opens shows the Client ID and the Client Secret, and the secret is shown only this once. Save it now; after the dialog closes, your only option is Reset secret on the Authentication tab.
2
Set the creator surface URL
Enter it in Embed settings on App details, or serve an App Manifest with an on-platform
access block.app-manifest.json
access.url is the creator surface URL Fanvue loads in the iframe. Set OAUTH_REDIRECT_URI to the first entry in oauth.redirectUris. No browser ever visits it, but the token exchange fails when the two differ. The access reference defines every field.3
Connect the domain and submit
Enter
your-app.com in App domain on the App details tab and confirm the Versions tab shows Up to date. Complete the listing and click Submit for review. The access block takes effect on submission.Hosting
Serve the creator surface overhttps with a browser-trusted certificate, and serve the manifest at https://<app domain>/app-manifest.json with no redirect. The client secret stays on your server.
Fanvue can only frame a page whose Content-Security-Policy allows it. withFanvueHeaders(nextConfig, options?) adds the headers every surface needs and merges them with the rules your next.config already declares. Your own rules come after Fanvue’s, so a Content-Security-Policy you set yourself wins.
next.config.mjs
One
frame-ancestors value serves production and development. The CORS rules on /api/* let your surface call your own API routes cross-origin. The wildcard origin is safe because the session travels in the Authorization header, never in a cookie. Pass { includeApiCors: false, apiPathPattern: null, extraAllowedHeaders: null, extraExposedHeaders: null } only if your app answers CORS itself. Pass permissions: ["microphone"] to allow the microphone for your origin (microphone=(self)) when your fan experience requests it; see Microphone access.
fanvueHeaderRules(options?) returns the same rules as an array for a headers() you compose by hand.
Authenticate with the SDK
Install the package, then add one server route and one client component.1
Add the session exchange route
createConfig() from the on-platform entrypoint reads the OAUTH_* variables plus FANVUE_PLATFORM_URL, which defaults to https://www.fanvue.com.app/api/fanvue/session/route.ts
POST { "token": "<session token>" }, runs the exchange, fetches the creator’s profile and answers { "jwt": "<session JWT>" }. The JWT is signed with SESSION_SECRET and holds the Fanvue tokens.2
Exchange the token on the client
useEmbeddedAuth() reads ?token= on mount, posts it to /api/fanvue/session, and stores the returned JWT in sessionStorage under fanvue:jwt. useAuth() exposes the JWT and authFetch, which adds Authorization: Bearer <jwt> to your own API calls and stores any X-Updated-Session header it receives.app/embedded/page.tsx
status is one of idle (no token in the URL and no stored JWT), exchanging, authenticated or error. On error, the error field holds one of:- the route’s error string
exchange_failed, when the response carried neithererrornorjwtnetwork_error, when the request never completed
3
Call the Fanvue API from your own routes
getAuthenticatedClient({ sessionSecret, config }) from the on-platform entrypoint reads the Bearer JWT, verifies it and returns { client, refreshedJwt }. When the access token was within 30 seconds of expiry, the SDK refreshes it and returns the re-signed JWT as refreshedJwt. Set it on the response as X-Updated-Session (HEADER_UPDATED_SESSION) so authFetch stores it.app/api/me/route.ts
Outside Next.js
useEmbeddedAuth posts to /api/fanvue/session and expects { jwt } back. On another server framework, implement that route with exchangeSessionToken(config, token) and createSessionJwt(secret, payload) from the core entrypoint, and pass exchangePath if the route lives elsewhere.
getSessionTokenFromUrl(window.location.href) and post it yourself. For a server that can’t run the SDK at all, follow the manual flow.
Session routes for apps with a token store
createCreatorSessionHandler(deps) and createFanSessionHandler(deps) are alternative bootstrap routes for apps that keep an encrypted token store and issue their own app sessions. Tokens, encryption and logging covers them alongside the token store.
Both apply a per-IP rate limit through the RateLimiter you inject. The defaults are SDK defaults, not platform limits, and deps.rateLimit overrides them.
createInMemoryRateLimiter() is the process-local default and tracks at most 10,000 keys (MAX_TRACKED_RATE_LIMIT_KEYS). On serverless hosts each instance counts separately, so implement RateLimiter over a shared store when the limit must hold. createSessionExchangeHandler applies no limiter.
Work on the creator’s behalf in the background
getAuthenticatedClient refreshes tokens only inside a live Bearer session. To call the API after the iframe closes, persist the refresh token when the exchange completes by passing onTokens to createSessionExchangeHandler.
app/api/fanvue/session/route.ts
onTokens receives the raw TokenResponse and the FanvueUser. If it throws, the exchange fails with 502, so the creator never gets a session whose tokens weren’t stored. Encrypt the tokens at rest and refresh them with compare-and-swap through the SDK’s token store.
Match the creator’s theme
Fanvue appends the creator’s colour scheme to both the creator and fan surface URLs as?theme=light or ?theme=dark. useEmbeddedAuth returns it as theme, typed FanvueTheme | null. It’s null when the page is opened outside Fanvue, so fall back to a default.
getThemeFromUrl(window.location.href) from the core entrypoint returns the same value. The theme parameter is not single-use, so any client code can read it from the URL.
How authentication works
Fanvue opens your creator surface URL with two query parameters.?token= carries a short-lived, single-use session token, which proves that this creator is using your app inside Fanvue right now. ?theme= carries the creator’s colour scheme.
Your server trades the session token for OAuth access and refresh tokens. exchangeSessionToken runs that exchange with PKCE and state, and createSessionExchangeHandler wraps it in a route. Your client secret and tokens never leave your server. The manual flow lists the requests for a server that can’t run the SDK.
The tokens carry the scopes registered on your app in the Developer Area, plus openid and offline_access, so they always include a refresh token. OAUTH_SCOPES applies only to off-platform login.
What your iframe can and cannot do
Fanvue renders every creator surface and fan surface in a sandboxed iframe. No app can widen the sandbox.Environments
Set the base URLs through the variablescreateConfig reads. Production values are the defaults.
Checklist
Check these before you go live.OAUTH_REDIRECT_URIequals the first redirect URI registered on your app. The redirect URI is never visited.- The session token is short-lived and single-use. Exchange it immediately, send it only to your own server, and never store it. If a creator leaves the surface open and acts much later, reopening the surface issues a fresh token.
- The client secret stays on your server. The SDK generates PKCE and verifies
stateon every exchange, so the exchange route is the only server code that handles the session token.
Appendix: the manual flow
This is everythingexchangeSessionToken does, written out for a server that can’t run the SDK.
Endpoints
{PLATFORM}, {AUTH} and {API} are the base URLs in the Environments table.
redirect_uri at the token exchange must equal the first redirect URI registered on your app. The authorise-on-behalf endpoint answers these errors:
Frontend
Readtoken and theme from the URL. Send the token to your own server and nowhere else.
Backend
The server generates PKCE andstate, asks the platform for a code, then exchanges it. Node 18 or later.
refresh_token. Store the new value when it is present, and keep the old one when it is absent. The SDK’s session helpers do exactly that. Refresh tokens rotate and are single-use has the rotation rules.