Better Auth: Self-Hosted Authentication for Cloudflare Workers for Openclaw

A comprehensive self-hosted authentication framework for TypeScript and Cloudflare Workers with native support for 15+ enterprise-grade plugins.

veeramanikandanr48
v0.1.0
Jan 31, 2026
1
2.6k
13

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install better-auth

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install better-auth using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Better Auth: Self-Hosted Authentication for Cloudflare Workers?

Better Auth is a powerful, open-source alternative to proprietary authentication services, specifically engineered for the TypeScript ecosystem and Cloudflare Workers environment. It provides developers with a robust Openclaw Skills toolkit to implement secure, scalable authentication using D1 databases through Drizzle ORM or Kysely. This framework is designed to handle everything from basic email/password sign-ins to complex enterprise requirements like SAML 2.0, SCIM provisioning, and multi-tenant organization management.

By leveraging better-auth, teams can reduce their development overhead by up to 97%, as the system automatically generates over 80 production-ready REST endpoints. This Openclaw Skills resource ensures that security best practices—such as JWT key rotation, stateless session management, and rate limiting—are baked into your application from day one without requiring extensive manual boilerplate code.

Better Auth: Self-Hosted Authentication for Cloudflare Workers Use Cases

  • Deploying self-hosted authentication on Cloudflare Workers using D1 databases for maximum data sovereignty.
  • Building multi-tenant SaaS applications with integrated organization management and role-based access control.
  • Implementing modern security standards including Passkeys, 2FA, and Magic Link authentication.
  • Transitioning from high-cost providers like Clerk or Auth.js to a customizable Openclaw Skills solution.
  • Creating custom OAuth 2.1 providers to secure internal APIs or third-party service integrations.

How Better Auth: Self-Hosted Authentication for Cloudflare Workers Works

  1. Database initialization occurs via Drizzle or Kysely to bridge the gap for Cloudflare D1 which lacks a direct better-auth adapter.
  2. The auth instance is instantiated using a factory pattern within the Cloudflare Worker request handler to ensure environment bindings are correctly injected.
  3. Desired plugins such as Two-Factor Authentication, Stripe, or Organization are registered in the configuration array to expand functionality.
  4. The auth.handler() function is exposed via HTTP routes, automatically enabling 80+ REST endpoints for client-side and mobile interaction.
  5. Server-side logic utilizes the auth.api.* methods to perform secure session validation and administrative tasks within middleware or background workers.

Better Auth: Self-Hosted Authentication for Cloudflare Workers Setup

To begin using this Openclaw Skills resource, first install the necessary dependencies:

npm install better-auth drizzle-orm @cloudflare/workers-types

Ensure your wrangler.toml includes the necessary compatibility flag for AsyncLocalStorage support:

# wrangler.toml
compatibility_flags = ["nodejs_compat"]

Initialize your authentication configuration within your worker:

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

export const auth = betterAuth({
  database: drizzleAdapter(db, { provider: "sqlite" }),
  emailAndPassword: { enabled: true },
  // ...additional configuration
});

Better Auth: Self-Hosted Authentication for Cloudflare Workers Data Schema & Taxonomy

The better-auth skill manages its data through a structured relational schema typically handled by Drizzle ORM. Below is an overview of the primary metadata organization:

Table Purpose Key Metadata
user Core identity email, name, role, image, emailVerified
session Active connections userId, token, expiresAt, ipAddress
account OAuth links providerId, accountId, accessToken
organization Multi-tenancy name, slug, logo, metadata
api_key Programmatic access key, userId, rateLimitMax, expiresAt

Note: For Cloudflare D1 compatibility, Ensure that updated_at fields are nullable to avoid insertion constraints during organization or team creation.

Better Auth: Self-Hosted Authentication for Cloudflare Workers Advanced Features

  • Stateless session management for high-performance edge computing using signed JWT or JWE cookies.
  • Comprehensive Admin Plugin providing ready-to-use endpoints for user banning, role assignment, and account impersonation.
  • Native OAuth 2.1 Provider capabilities for building your own secure authorization server with PKCE and OIDC support.
  • Automated rate limiting with secondary storage support via Cloudflare KV for distributed systems.
  • Integrated database hooks that allow execution of custom logic before or after user, session, and account modifications.
  • Interactive Scalar UI documentation automatically generated at /api/auth/reference using the OpenAPI plugin.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*