npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@onlyfansapi/auth

v2.0.2

Published

Framework agnostic library to embed OnlyFans Authentication in your app using OnlyFansAPI.com/auth

Readme

@onlyfansapi/auth

A framework-agnostic library to embed OnlyFans Authentication in your app using OnlyFansAPI.com/auth.

Features

  • 🚀 Framework Agnostic - Works with React, Vue, Angular, vanilla JS, or any framework
  • 🎨 Beautiful Modal UI - Modern, responsive modal with smooth animations
  • 🔒 Secure Communication - PostMessage-based communication with origin validation
  • ⌨️ Keyboard Support - ESC key to close modal
  • 📱 Mobile Friendly - Responsive design that works on all devices
  • 🎯 TypeScript Support - Full type definitions included
  • 📦 Modern Bundling - Built with tsup for optimal bundle size and compatibility

Installation

npm install @onlyfansapi/auth
# or
yarn add @onlyfansapi/auth
# or
pnpm add @onlyfansapi/auth
# or
bun install @onlyfansapi/auth

Quick Start

import { startOnlyFansAuthentication } from "@onlyfansapi/auth";

// Start authentication
startOnlyFansAuthentication("ofapi_cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
  onSuccess: (data) => {
    console.log("Authentication successful:", data);
    // data.accountId - The authenticated account ID
    // data.username - The authenticated username
    // data.response - Full response from the API
  },
  onError: (error) => {
    console.error("Authentication failed:", error);
    // error.message - Error message
    // error.code - Error code (if available)
    // error.details - Additional error details (if available)
  },
});

API Reference

startOnlyFansAuthentication(clientSessionToken, options)

Opens a modal with an iframe containing the OnlyFans authentication flow.

Parameters:

  • clientSessionToken (string): Your client session token - Get your Client Session Token from https://docs.onlyfansapi.com/api-reference/client-sessions/create-client-session
  • options (object):
    • onSuccess(data: AuthSuccessData) (function): Callback when authentication succeeds
    • onError(error: AuthFailureError) (function): Callback when authentication fails

Example:

startOnlyFansAuthentication("ofapi_cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
  onSuccess: (data) => {
    // Handle successful authentication
    const { accountId, username } = data;
    console.log(`Welcome ${username}!`);
  },
  onError: (error) => {
    // Handle authentication error
    console.error("Auth failed:", error.message);
  },
});

closeOnlyFansAuthentication()

Programmatically closes the authentication modal.

Example:

import { closeOnlyFansAuthentication } from "@onlyfansapi/auth";

// Close the modal
closeOnlyFansAuthentication();

Data Types

AuthSuccessData

interface AuthSuccessData {
  accountId: string; // The authenticated account ID
  username: string; // The authenticated username
  onlyfansData: {
    id: number | string; // OnlyFans user ID
    username: string; // OnlyFans username
    email: string; // OnlyFans email
    avatar_url: string | null; // OnlyFans avatar URL
    name: string; // OnlyFans display name
  };
}

AuthFailureError

interface AuthFailureError {
  message: string; // Error message, eg. "Wrong email or password"
}

Framework Examples

React

import React from "react";
import { startOnlyFansAuthentication } from "@onlyfansapi/auth";

function AuthButton() {
  const handleAuth = () => {
    startOnlyFansAuthentication("ofapi_cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
      onSuccess: (data) => {
        console.log("Success:", data);
      },
      onError: (error) => {
        console.error("Error:", error);
      },
    });
  };

  return <button onClick={handleAuth}>Authenticate with OnlyFans</button>;
}

Vue

<template>
  <button @click="handleAuth">Authenticate with OnlyFans</button>
</template>

<script setup>
import { startOnlyFansAuthentication } from "@onlyfansapi/auth";

const handleAuth = () => {
  startOnlyFansAuthentication("ofapi_cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
    onSuccess: (data) => {
      console.log("Success:", data);
    },
    onError: (error) => {
      console.error("Error:", error);
    },
  });
};
</script>

Vanilla JavaScript

<button onclick="authenticate()">Authenticate with OnlyFans</button>

<script>
  import { startOnlyFansAuthentication } from "@onlyfansapi/auth";

  function authenticate() {
    startOnlyFansAuthentication("ofapi_cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", {
      onSuccess: (data) => {
        console.log("Success:", data);
      },
      onError: (error) => {
        console.error("Error:", error);
      },
    });
  }
</script>

Modal Features

The authentication modal includes:

  • Responsive Design: Adapts to different screen sizes
  • Smooth Animations: Fade-in/fade-out with scale transitions
  • Close Button: Clickable × button in the top-right corner
  • Keyboard Support: Press ESC to close
  • Body Scroll Lock: Prevents background scrolling when modal is open
  • High Z-Index: Ensures modal appears above other content
  • Origin Validation: Secure postMessage communication

Security

  • All communication with the iframe is validated by origin
  • Only messages from the configured OnlyFansAPI.com domain are accepted
  • Client session tokens are passed securely via URL parameters

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+

License

MIT