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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@contentgrowth/content-auth

v0.2.5

Published

Better Auth wrapper with UI components for Cloudflare Workers & Pages

Downloads

1,228

Readme

@contentgrowth/content-auth

A wrapper around Better Auth designed specifically for Cloudflare Workers and Cloudflare Pages, providing both backend Hono middleware and pre-built React frontend components.

Features

  • 🔐 Secure Authentication: Powered by Better Auth.
  • Cloudflare Ready: Optimized for Workers and Pages (D1 Database support).
  • 🧩 Hono Integration: Easy middleware integration for your Hono API.
  • ⚛️ React Components: Pre-built, customizable UI components for login/signup.
  • 📦 Type Safe: Full TypeScript support.

Installation

npm install @contentgrowth/content-auth
# or
yarn add @contentgrowth/content-auth
# or
pnpm add @contentgrowth/content-auth

Usage

1. Backend Setup (Cloudflare Workers/Pages + Hono)

Create your authentication API using the createAuthApp helper. This sets up the necessary routes for Better Auth.

// src/index.ts
import { Hono, createAuthApp } from '@contentgrowth/content-auth/backend';

type Bindings = {
  DB: D1Database;
  BETTER_AUTH_SECRET: string;
  BASE_URL: string;
};

const app = new Hono<{ Bindings: Bindings }>();

app.mount('/api/auth', async (c) => {
    // Initialize the auth app
    const { app: authApp } = createAuthApp({
        database: c.env.DB,
        secret: c.env.BETTER_AUTH_SECRET,
        baseUrl: c.env.BASE_URL, // e.g., http://localhost:5173 or https://your-app.pages.dev
    });
    
    return authApp.fetch(c.req.raw, c.env, c.executionCtx);
});

export default app;

Configuration Options (createAuthApp)

| Option | Type | Description | | source | --- | --- | | database | D1Database | any | Your Cloudflare D1 binding or a Drizzle instance. | | secret | string | A secret key for signing tokens. | | baseUrl | string | The base URL of your application. | | provider | 'sqlite' | 'postgres' | 'mysql' | (Optional) Database provider. Defaults to 'sqlite' (for D1). | | ... | BetterAuthOptions | Any other Better Auth configuration options. |

Using without Hono (Standard Cloudflare Worker)

If you are not using Hono, you can use the createAuth function directly in your fetch handler.

import { createAuth } from '@contentgrowth/content-auth/backend';

export default {
  async fetch(request, env, ctx) {
    const auth = createAuth({
      database: env.DB,
      secret: env.BETTER_AUTH_SECRET,
      baseUrl: env.BASE_URL
    });

    // Manually handle the auth routes
    if (request.url.includes("/api/auth")) {
      return auth.handler(request);
    }

    return new Response("Hello World");
  }
}

Using with Other Databases (Postgres/MySQL)

You can use this package with any database supported by Drizzle ORM (Postgres, MySQL, etc.) on any platform (Node.js, Bun, etc.).

  1. Initialize your Drizzle instance.
  2. Pass it to createAuthApp.
  3. Set the provider option.
import { Hono } from 'hono';
import { createAuthApp } from '@contentgrowth/content-auth/backend';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Client } from 'pg';

const client = new Client({
  connectionString: process.env.DATABASE_URL,
});
await client.connect();
const db = drizzle(client);

const app = new Hono();

const { app: authApp } = createAuthApp({
    database: db,
    secret: process.env.BETTER_AUTH_SECRET,
    baseUrl: process.env.BASE_URL,
    provider: "postgres", // or "mysql"
});

app.route('/api/auth', authApp);

2. Frontend Setup (React)

Use the provided AuthForm component to render a sign-in/sign-up form.

// src/App.tsx
import React from 'react';
import { AuthForm } from '@contentgrowth/content-auth/frontend';
import '@contentgrowth/content-auth/styles.css'; // Import default styles

export default function App() {
  return (
    <div className="min-h-screen flex items-center justify-center bg-gray-50">
      <div className="max-w-md w-full">
        <h1 className="text-2xl font-bold text-center mb-6">Welcome Back</h1>
        
        <AuthForm 
          type="signin" // or "signup"
          onSuccess={() => {
            console.log('User authenticated!');
            window.location.href = '/dashboard';
          }}
        />
      </div>
    </div>
  );
}

Client Client

You can also use the authClient directly for custom implementations:

import { authClient } from '@contentgrowth/content-auth/client';

// Example: Sign in with email
await authClient.signIn.email({
    email: "[email protected]",
    password: "password123"
});

Database Setup

This package requires specific database tables to function. We provide a SQL schema template that you copy into your project and extend with your own tables.

Step 1: Initialize the Schema

Use the CLI to initialize the schema in your project:

npx content-auth init

This creates ./migrations/0000_auth.sql with all required auth tables.

Options:

  • -o, --output <path> — Custom output path (default: ./migrations/0000_auth.sql)
  • --force — Overwrite existing file
# Example: Custom output path
npx content-auth init -o ./db/migrations/0001_auth.sql

Step 2: Add Your Application Tables

Edit the copied file and add your application-specific tables at the bottom:

-- ... (auth tables from template above) ...

-- ==========================================
-- YOUR APPLICATION TABLES
-- ==========================================

CREATE TABLE IF NOT EXISTS my_entity (
    id TEXT PRIMARY KEY,
    org_id TEXT NOT NULL,  -- References organization.id
    name TEXT NOT NULL,
    created_at INTEGER
);

Step 3: Run Migrations

# For Cloudflare D1 (local)
wrangler d1 migrations apply DB --local

# For Cloudflare D1 (remote)
wrangler d1 migrations apply DB --remote

Extending Auth Tables

You can add extra columns to any auth table for your business needs. Just ensure you keep all existing columns — they are required by Better Auth.

-- Example: Adding custom fields to organization
CREATE TABLE IF NOT EXISTS organization (
    -- Required columns (keep these)
    id TEXT PRIMARY KEY,
    name TEXT NOT NULL,
    slug TEXT UNIQUE,
    logo TEXT,
    createdAt TIMESTAMP NOT NULL,
    metadata TEXT,
    
    -- Your custom columns
    domain TEXT,
    is_verified BOOLEAN DEFAULT FALSE,
    billing_tier TEXT DEFAULT 'free'
);

Schema Reference

| Table | Purpose | |-------|---------| | user | User accounts | | session | Active sessions | | account | OAuth/credential providers | | verification | Email/token verification | | organization | Teams/orgs (org plugin) | | member | Org membership (org plugin) | | invitation | Pending invites (org plugin) |

For detailed field definitions, see schema/auth.sql or the Better Auth Drizzle Adapter documentation.

License

MIT