better-auth

Configure self-hosted authentication for TypeScript projects on Cloudflare Workers.

18|4|Updated Jan 15, 2026
One-click install
npx skills add https://github.com/ataschz/tanstack-start-mastra-example --skill better-auth-ataschz
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth
Source: https://github.com/ataschz/tanstack-start-mastra-example/tree/main/.agents/skills/better-auth
Command: npx skills add https://github.com/ataschz/tanstack-start-mastra-example --skill better-auth-ataschz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires better-auth, drizzle-orm, drizzle-kit, @cloudflare/workers-types, hono, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve?

This Skill enables self-hosted authentication for TypeScript projects running on Cloudflare Workers, providing a comprehensive plugin ecosystem to support OAuth, 2FA, SSO, organizations, and RBAC without relying on external hosted auth services.

Core Features & Use Cases

  • OAuth 2.1 Provider: Build your own OAuth provider with PKCE, consent flows, and JWT or opaque tokens.
  • SSO & RBAC: Enterprise Single Sign-On with SSO and role-based access control for multi-tenant apps.
  • Organizations & Admin: Multi-tenant organization management and admin controls with auditing and security hooks.
  • Flexible sessions: Stateless cookies or server-side sessions with KV or D1 storage, plus rate limiting.
  • Use Case: Deploy a SaaS app that requires self-hosted auth, customer admins, and secure session management.

Quick Start

Install dependencies and configure D1 with Drizzle or Kysely, set BETTER_AUTH_SECRET and BETTER_AUTH_URL, then run the development server and call /api/auth endpoints to sign in or sign up.

Frequently Asked Questions about better-auth

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up self-hosted authentication for a TypeScript app on Cloudflare Workers?

To set up self-hosted authentication for a TypeScript app on Cloudflare Workers, install the required dependencies, configure D1 storage with Drizzle or Kysely, set your BETTER_AUTH_SECRET and BETTER_AUTH_URL, and expose endpoints via auth.handler().

Can I implement multi-tenant organizations and RBAC in a Cloudflare Workers SaaS application?

Yes, you can implement multi-tenant organizations and RBAC in a Cloudflare Workers SaaS application using built-in organization and admin plugins, which provide role-based access control, auditing, and security hooks across D1-backed storage.

Does self-hosted auth for Cloudflare Workers support OAuth providers and 2FA?

Self-hosted auth for Cloudflare Workers supports OAuth providers and 2FA through optional plugins, allowing you to build an OAuth 2.1 provider with PKCE and add twoFactor authentication for secure session management.

What is the best way to manage user sessions with D1 in a TypeScript Cloudflare Worker?

The best way to manage user sessions with D1 in a TypeScript Cloudflare Worker is using flexible stateless cookies or server-side sessions stored in KV or D1, enhanced with built-in rate limiting for security.

Do I need Drizzle ORM to handle authentication in a Hono application on Cloudflare Workers?

You do not need Drizzle ORM specifically to handle authentication in a Hono application; you can use either Drizzle ORM or Kysely to manage your D1-backed storage when configuring your self-hosted auth server.

Related Skills