Skip to content
Fans API logo, publisher of the OnlyFans auth npm package @onlyfansapi/auth

Fans API · APIs and developer tools

OnlyFans Auth npm Package: @onlyfansapi/auth

TL;DR

  • The OnlyFans auth npm package, @onlyfansapi/auth, adds a Connect OnlyFans modal to your own web app, so creators link their accounts to Fans API without leaving your site.
  • It exports one main function, startOnlyFansAuthentication, which takes a short-lived client session token from your backend and passes the new account ID to your callback when the creator signs in.
  • Skip it if you connect accounts yourself in the Fans API dashboard, or if you're building a native mobile app rather than a web page.
Price
Free
Product
Fans API
Platforms
Web apps in React, Vue, Svelte, Angular or plain JavaScript; a backend to create session tokens
Free trial
The package is free (MIT); connected accounts run on a Fans API plan, including the Free plan

What the OnlyFans auth npm package is

The OnlyFans auth npm package, @onlyfansapi/auth, is a free JavaScript library that adds a “Connect OnlyFans” button flow to your own web app. A creator clicks the button, signs in to OnlyFans inside a modal, and the account becomes connected to your Fans API team. Your code gets back an account ID it can use in every later API call.

Fans API publishes the package, under its original OnlyFansAPI.com name, and the source sits in the onlyfansapi/javascript repository on GitHub. Fans API describes it as “Login with OnlyFans” for your app. It is one of four ways to connect an account, next to the dashboard, the Auth+ iPhone app and the raw API flow. It belongs to our OnlyFans developer tools category, alongside the API for OnlyFans that the connected accounts are used with.

Key features of the OnlyFans auth npm package

The package does one job: it gets a creator from “not connected” to “connected” without you building the sign-in screens. Here is what that covers.

One function for the whole flow

The main export is startOnlyFansAuthentication(clientSessionToken, { onSuccess, onError }). It opens a modal with an iframe, runs the sign-in, and calls one of your two callbacks. A second export, closeOnlyFansAuthentication(), closes the modal from your code, and the ESC key closes it for the user. The quick start guide lists both functions with their types.

2FA handled inside the modal

Creators with two-factor authentication enter their code in the same modal. The connection guide says the package handles the OTP and selfie steps for you, so you don’t build a second screen or poll for status yourself.

Client session tokens instead of API keys

The browser never sees your API key. Your backend creates a client session token, which starts with ofapi_cs_, and hands it to the page. You can attach a client_reference_id, such as your own user ID, and a proxy_country of us or uk. The installation guide walks through creating the token.

Framework agnostic, with types

The docs show the same call in React, Vue, Svelte, Angular and a plain HTML page. The package ships ES module and CommonJS builds, TypeScript definitions for AuthSuccessData and AuthFailureError, and a browser global for pages without a bundler. It has no runtime dependencies.

OnlyFans auth npm package code sample

The install line and the browser call come from the package README and the quick start guide. The server route is shortened from the Next.js and Prisma example in the same docs. pnpm, yarn and bun work with the same package name.

npm install @onlyfansapi/auth
// app/api/client-session/route.ts (server only: your API key stays here)
export async function POST() {
  const response = await fetch(
    "https://app.onlyfansapi.com/api/client-sessions",
    {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer ${process.env.OFAPI_API_KEY}`,
      },
      body: JSON.stringify({ display_name: "My App / Model: Jane Doe" }),
    },
  );
  const { data } = await response.json();
  return Response.json({ token: data.token }); // starts with ofapi_cs_
}
// In the browser, when the creator clicks "Connect OnlyFans"
import { startOnlyFansAuthentication } from "@onlyfansapi/auth";

const { token } = await fetch("/api/client-session", { method: "POST" }).then(
  (r) => r.json(),
);

startOnlyFansAuthentication(token, {
  onSuccess: (data) => {
    // Save data.accountId; you pass it to every later API call
    console.log(`Connected @${data.username} as ${data.accountId}`);
  },
  onError: (error) => {
    console.error("Authentication failed:", error.message);
  },
});

In version 2.0.2, onSuccess receives accountId, username and an onlyfansData object with the creator’s ID, name, email and avatar URL. onError receives a message. Save the account ID in your own database, then call the API with it from your server, or use one of the OnlyFans API SDKs for typed calls.

Is the OF Auth npm package safe to use?

The package keeps your secrets out of the browser by design, and the docs describe the rest of the safety model. Your API key only ever runs on your server, to create a client session token. The page gets that token, which the docs say is built for client-side use but should still be handled with care. The best-practices section recommends fetching it from your backend rather than hardcoding it.

The docs list four protections inside the library. Messages from the iframe are checked by origin, only messages from the Fans API domain are accepted, the token is passed to the iframe in its URL, and HTTPS is required in production. The creator types their OnlyFans password into the Fans API iframe, not into your app, so your servers never handle it. Fans API’s connection guide says stored credentials are kept in its database and that even its engineers can’t see them. We know of no independent security audit of the package.

OnlyFans doesn’t offer a public developer API, and Fans API is an independent service. Its terms say OnlyFans may restrict third-party access, so connect only accounts you own or are authorized to manage.

Pricing

The package is free under the MIT license. What you pay for is the Fans API plan behind it, because each account a creator connects counts toward your plan’s account limit. The Free plan includes one account and 100 welcome credits, the $69 plan includes one account, and the $299 plan includes five accounts, then $29 for each extra. Enterprise is priced on request. Check Fans API pricing before you launch, since the plan you need depends on how many creators will connect through your app.

Who it’s for, and who should skip it

The OF Auth package is for developers building a product that creators or agency staff sign in to themselves. Think of a SaaS dashboard, a chatter tool, an analytics app or an agency portal where each new creator connects their own account during onboarding. It suits teams who’d rather not build a sign-in form, a 2FA step and status polling, and who already run a backend for the API calls that follow.

Skip it if your agency connects every account by hand in the Fans API dashboard; the dashboard already does this without code. Skip it as well if you’re building a native iOS or Android app, because the docs only cover web pages. Creators whose accounts use Face Authentication v2 will need the Auth+ iPhone app either way. And once accounts are connected, events like new messages come through OnlyFans webhooks, which this package doesn’t set up.

Pros and cons

Pros

  • Free and open source under the MIT license
  • One function call opens the whole sign-in flow, including 2FA codes, in a modal
  • Works with React, Vue, Svelte, Angular or plain JavaScript, with TypeScript types included
  • No runtime dependencies, and the compiled module is under 4 kB
  • Your API key stays on your server; the browser only sees a client session token

Cons

  • You still need a backend route to create client session tokens, so it isn't a frontend-only install
  • Built for web pages; the docs don't cover native iOS or Android apps
  • Accounts with Face Authentication v2 can't connect this way and need the Auth+ iPhone app instead
  • The docs examples mention fields such as data.response and error.code that the 2.0.2 type definitions don't include
  • Only US and UK proxy countries are available for new connections

Frequently Asked Questions

Short answers to the questions agencies ask most.

What does @onlyfansapi/auth do?

It opens a modal in your web app where a creator signs in to OnlyFans and connects the account to Fans API. The modal is an iframe served by Fans API, and it handles the email and password step and any 2FA code. When the creator finishes, your onSuccess callback receives the new account ID and the OnlyFans username. From then on, you use that account ID in API calls, the same way you would for an account connected in the dashboard.

Is the OnlyFans auth npm package free?

Yes. The package is published under the MIT license and costs nothing to install. What it connects is not free beyond the Free plan, because every connected account counts against your Fans API plan. The Free plan includes one account and 100 welcome credits. The $69 plan also includes one account, and the $299 plan includes five, then $29 for each extra account.

Do I need a backend to use it?

Yes. The modal needs a client session token that starts with ofapi_cs_, and you create it by calling the Create Client Session endpoint with your secret API key. That call has to run on a server, because a key in browser code is visible to anyone. A small route in Next.js, Express or any other backend is enough. The docs include a full Next.js and Prisma example that does exactly this.

Which frameworks does it support?

The package is framework agnostic. The docs show working examples for React, Vue, Svelte, Angular and plain JavaScript in an HTML page. It ships ES module and CommonJS builds plus TypeScript definitions, so it fits most bundlers. It also exposes a browser global, window.OnlyFansAPI.Auth, for pages without a build step. Native mobile apps aren't covered by the docs.

Does it work with 2FA?

Yes for code-based 2FA. The connection guide says the package handles the OTP and selfie steps inside the embedded modal, so creators with SMS or authenticator codes can finish on their own. Accounts with Face Authentication v2 are different. The guide says dashboard and API sessions fail for those, and it points to the Auth+ iPhone app instead.

What's the difference between this and the Fans API SDKs?

They do different jobs. The auth package runs in the browser and connects a creator's OnlyFans account to Fans API. The SDKs run on your server and call the API for accounts that are already connected, for example to read chats or list fans. Most apps that let creators sign up use both. The auth package handles onboarding, and an SDK or plain HTTP calls handle everything after.

Verdict

The OF Auth npm package is the right choice if you're building a SaaS tool or agency portal and want creators to connect their own OnlyFans accounts inside your app. It saves you from building a sign-in form, a 2FA step and the polling behind them, and it costs nothing beyond your Fans API plan. It doesn't do anything after the connection; for that you use the API or an SDK. If your team connects accounts by hand, the dashboard is simpler.

Best for: Apps that need a drop-in OnlyFans login flow

Fans API logo

OF Auth npm package

Free

Visit Site