# Connect Creator Accounts Without Building a Login Flow (@onlyfansapi/auth)

> Connect creator accounts without building a custom login flow. With @onlyfansapi/auth, the creator logs in with email, password and 2FA inside our secure modal.

**TL;DR**

- The `@onlyfansapi/auth` package replaces months of reverse-engineering with a fast integration for creator authentication.
- The creator logs in with email, password and 2FA inside our secure modal.
- Each connected account gets one dedicated mobile IP (US or UK), no rotation, on the Basic plan and up.
- The modal handles 2FA, and webhooks (Basic plan and up) notify you in near real-time of challenges like `accounts.otp_code_required`.

You can connect creator accounts without building a custom login flow by implementing the `@onlyfansapi/auth` library. This 1.5kB package provides a framework-agnostic setup where the creator logs in with email, password and 2FA inside our secure modal.

**Key Takeaways**

- The `@onlyfansapi/auth` package replaces months of reverse-engineering with a fast integration for creator authentication.
- The creator logs in with email, password and 2FA inside our secure modal.
- Each connected account gets one dedicated mobile IP (US or UK), no rotation, on the Basic plan and up.
- The modal handles 2FA, and webhooks (Basic plan and up) notify you in near real-time of challenges like `accounts.otp_code_required`.

## Better alternative to building custom auth flows for OnlyFans

The alternative to building a custom auth flow for OnlyFans is the official [Auth](https://fansapi.com/auth) library, built for this: it manages the entire login and verification process inside our secure modal. Agencies and developers building CRM systems or chat tools often spend months attempting to reverse-engineer client requests. These custom flows are widely reported to break when the platform updates its login. Our [OnlyFans API guide](/blog/onlyfans-api-guide) explains why reverse engineering keeps failing.

Instead of maintaining fragile infrastructure, teams use OnlyFansAPI to authenticate users directly. OnlyFansAPI runs each connected account on a dedicated mobile IP (Basic plan and up). Because the creator logs in inside our secure modal, you never store raw credentials on your own servers. OnlyFansAPI has run for 5+ years with zero bans.

## Why In-House Authentication Systems Fail

Custom authentication systems face constant maintenance overhead due to anti-bot protections.

The platform is widely reported to flag or limit login attempts originating from standard datacenter IPs. Multi-factor authentication adds another layer of complexity. Custom forms must programmatically handle time-based authenticator codes, email OTPs, SMS codes, and face verification challenges.

## What is @onlyfansapi/auth?

The [`@onlyfansapi/auth` on npm](https://www.npmjs.com/package/@onlyfansapi/auth) package is the official authentication library for the OnlyFans API. The 1.5kB script loads in 2ms on 4G internet and includes full TypeScript definitions. It works natively with React, Vue, Svelte, Angular, Next.js, and vanilla JavaScript. It connects OnlyFans accounts; Fansly accounts connect through `POST /api/fansly/authenticate`.

When integrated, the creator logs in with email, password and 2FA inside our secure modal. Your frontend receives the `accountId` in the `onSuccess` callback, and the `accounts.connected` webhook delivers the same ID to your backend; the password is entered only inside our secure modal. OnlyFansAPI has handled 300M+ API requests and webhooks, and 1,100+ companies use it. Our service is not a scraper. OnlyFansAPI uses automated risk controls to keep every account protected.

## How to Implement the Secure Modal

The authentication lifecycle follows a server-to-client handshake. Your API key stays on your backend, and only a temporary client session token reaches the browser.

### 1. Create a Client Session

Your backend makes an authenticated POST request to generate a session. You must include your API key in the header and a `display_name` in the body.

```http
POST https://app.fansapi.com/api/client-sessions
Authorization: Bearer <key>
Content-Type: application/json

{"display_name": "My Agency CRM", "client_reference_id": "my_crm_model_12345"}
```

### 2. Generate the Token

The API returns a temporary client session token in `data.token`, prefixed with `ofapi_cs_`. You send this token to your frontend application.

### 3. Launch the Modal

Your frontend calls `startOnlyFansAuthentication(token, { onSuccess, onError })`. The secure modal opens for the creator to input their authentication details.

### 4. Store the Account

The `onSuccess(data)` callback fires once the login completes. It returns `data.accountId` (where account IDs start with `acct_`) and `data.username`. You bind this `accountId` to the user profile in your database. The `client_reference_id` you set on the client session comes back on the `accounts.connected` webhook, so your backend can match the account to your user.

## Managing OTP and Session Webhooks

OnlyFansAPI reconnects expired sessions automatically and notifies you about session and 2FA events through webhooks (Basic plan and up) in near real-time. When an account requires verification out-of-band, your application receives JSON payloads to prompt the creator.

Available account webhook events include:

- `accounts.connected`: The creator successfully completes the modal login.
- `accounts.reconnected`: The account was reconnected.
- `accounts.session_expired`: The session expired and was reconnected automatically.
- `accounts.otp_code_required`: A 2FA or OTP code is needed to complete the connection.
- `accounts.face_otp_required`: Face verification is needed; the payload includes a `face_otp_verification_url`.
- `accounts.authentication_failed`: The session expired and could not be reconnected automatically, so the creator must log in again.

When you receive an `accounts.otp_code_required` event, your system reads the payload state. In the modal, a wrong code shows the retry screen. In the API flow, the attempt moves to `wrong_2fa_code_retry` and you re-submit a fresh code with `PUT /api/authenticate/{attempt_id}`, with no restart needed.

## Comparing Custom Auth to OnlyFansAPI

Implementing the standard authentication flow takes minutes compared to the months required for custom infrastructure. See the full integration details in the [Login with OnlyFans](https://docs.fansapi.com/auth) documentation.

| Feature | Custom Auth Flow | @onlyfansapi/auth |
| --- | --- | --- |
| **Implementation Time** | Months | Minutes |
| **Security** | Your servers handle raw passwords | Secure modal login |
| **MFA Support** | Requires custom parsers | Built-in OTP and 2FA handling |
| **Proxy Architecture** | Must manage your own proxies | One dedicated mobile IP per connected account (Basic and up) |