Skip to main content
Use the TypeScript SDK release candidate on your Next.js server to connect OnlyFans accounts. Your app keeps its own signed-in session. The account owner approves access on OFAuth, then returns to your app. If you want OFAuth to sign users into your app, follow the Better Auth guide.

Set up your integration

  1. Create an External Integration in the dashboard.
  2. Register http://127.0.0.1:3000/api/ofauth/callback for Sandbox.
  3. Open your app at 127.0.0.1 so its session cookie uses the same host as the callback.
  4. Store the client ID, secret, and callback URL on your server.
Use Better Auth Generic OAuth when Better Auth already owns application accounts. Otherwise, adapt the Express OAuth example to your App Router routes.

Add start and callback routes

  1. Read the initiating user and browser session from trusted server authentication.
  2. Create an authorization URL with OFAuthLink.createAuthorizationUrl, requesting only required scopes.
  3. Persist its state and PKCE verifier with that user, session, expiry, and registration version before redirecting.
  4. On return, atomically consume matching state for the same user and session. A foreign callback must not consume a legitimate attempt.
  5. Validate the issuer, parse the callback, exchange the code, and save tokens only if the registration version still matches.
  6. Redirect to an explicit account picker.
Handle access_denied as cancellation. Expired sessions, reused state, and mismatched callbacks require a new attempt. The resource SDK does not provide a second Next.js credential manager.

Choose an account and read its profile

List shared accounts with client.linkedAccounts.iterate() and show connected accounts in a picker. Save the chosen ID in your app, keyed by the same client and user. Check that it is still shared before each use. Create OFAuthClient with your auth system’s token getter and the selected linkedAccountId, then call client.access.profile.get(). See Choose an account for the code. Do not choose the first account in a shared list. An authorization can include several creators.

Recover access

When an account needs a reconnect, pause only that account and follow Handle account reconnects. The guide includes a session-bound return handler for completed, canceled, expired, and denied journeys. Retry a lost refresh response with the same stable client-bound refresh token. An invalid refresh grant requires authorization again. See Handle failures.