Skip to content
cccskills
FreePublished on GitHub

better-auth

Use this skill to add authentication and authorization to TypeScript applications with Better Auth. It covers email and social sign-in, sessions, database setup, two-factor authentication, passkeys, and access rules, with guidance for several web frameworks.

OriginalShow the original description

Implement authentication and authorization with Better Auth - a framework-agnostic TypeScript authentication framework. Features include email/password authentication with verification, OAuth providers (Google, GitHub, Discord, etc.), two-factor authentication (TOTP, SMS), passkeys/WebAuthn support, session management, role-based access control (RBAC), rate limiting, and database adapters. Use when adding authentication to applications, implementing OAuth flows, setting up 2FA/MFA, managing user sessions, configuring authorization rules, or building secure authentication systems for web applications.

Works withDiscordGitHub

Run score Not tested

See how to install

Good for

  • Adding email and password sign-in
  • Setting up Google or GitHub OAuth
  • Adding two-factor authentication or passkeys
  • Managing sessions and protected routes
  • Configuring organization roles and access rules

Files included (10)

  • SKILL.md7.2 KB
  • references/advanced-features.md10.4 KB
  • references/database-integration.md10.3 KB
  • references/email-password-auth.md8.4 KB
  • references/oauth-providers.md9.1 KB
  • scripts/.coverage52.0 KB
  • scripts/better_auth_init.py16.0 KB
  • scripts/requirements.txt402 B
  • scripts/tests/.coverage52.0 KB
  • scripts/tests/test_better_auth_init.py15.1 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Better Auth Skill

Better Auth is comprehensive, framework-agnostic authentication/authorization framework for TypeScript with built-in email/password, social OAuth, and powerful plugin ecosystem for advanced features.

When to Use

  • Implementing auth in TypeScript/JavaScript applications
  • Adding email/password or social OAuth authentication
  • Setting up 2FA, passkeys, magic links, advanced auth features
  • Building multi-tenant apps with organization support
  • Managing sessions and user lifecycle
  • Working with any framework (Next.js, Nuxt, SvelteKit, Remix, Astro, Hono, Express, etc.)

Quick Start

Installation

npm install better-auth
# or pnpm/yarn/bun add better-auth

Environment Setup

Create .env:

BETTER_AUTH_SECRET=<generated-secret-32-chars-min>
BETTER_AUTH_URL=http://localhost:3000

Basic Server Setup

Create auth.ts (root, lib/, utils/, or under src/app/server/):

import { betterAuth } from "better-auth";

export const auth = betterAuth({
  database: {
    // See references/database-integration.md
  },
  emailAndPassword: {
    enabled: true,
    autoSignIn: true
  },
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
    }
  }
});

Database Schema

npx @better-auth/cli generate  # Generate schema/migrations
npx @better-auth/cli migrate   # Apply migrations (Kysely only)

Mount API Handler

Next.js App Router:

// app/api/auth/[...all]/route.ts
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";

export const { POST, GET } = toNextJsHandler(auth);

Other frameworks: See references/email-password-auth.md#framework-setup

Client Setup

Create auth-client.ts:

import { createAuthClient } from "better-auth/client";

export const authClient = createAuthClient({
  baseURL: process.env.NEXT_PUBLIC_BETTER_AUTH_URL || "http://localhost:3000"
});

Basic Usage

// Sign up
await authClient.signUp.email({
  email: "user@example.com",
  password: "secure123",
  name: "John Doe"
});

// Sign in
await authClient.signIn.email({
  email: "user@example.com",
  password: "secure123"
});

// OAuth
await authClient.signIn.social({ provider: "github" });

// Session
const { data: session } = authClient.useSession(); // React/Vue/Svelte
const { data: session } = await authClient.getSession(); // Vanilla JS

Feature Selection Matrix

FeaturePlugin RequiredUse CaseReference
Email/PasswordNo (built-in)Basic authemail-password-auth.md
OAuth (GitHub, Google, etc.)No (built-in)Social loginoauth-providers.md
Email VerificationNo (built-in)Verify email addressesemail-password-auth.md
Password ResetNo (built-in)Forgot password flowemail-password-auth.md
Two-Factor Auth (2FA/TOTP)Yes (twoFactor)Enhanced securityadvanced-features.md
Passkeys/WebAuthnYes (passkey)Passwordless authadvanced-features.md
Magic LinkYes (magicLink)Email-based loginadvanced-features.md
Username AuthYes (username)Username loginemail-password-auth.md
Organizations/Multi-tenantYes (organization)Team/org featuresadvanced-features.md
Rate LimitingNo (built-in)Prevent abuseadvanced-features.md
Session ManagementNo (built-in)User sessionsadvanced-features.md

Auth Method Selection Guide

Choose Email/Password when:

  • Building standard web app with traditional auth
  • Need full control over user credentials
  • Targeting users who prefer email-based accounts

Choose OAuth when:

  • Want quick signup with minimal friction
  • Users already have social accounts
  • Need access to social profile data

Choose Passkeys when:

  • Want passwordless experience
  • Targeting modern browsers/devices
  • Security is top priority

Choose Magic Link when:

  • Want passwordless without WebAuthn complexity
  • Targeting email-first users
  • Need temporary access links

Combine Multiple Methods when:

  • Want flexibility for different user preferences
  • Building enterprise apps with various auth requirements
  • Need progressive enhancement (start simple, add more options)

Core Architecture

Better Auth uses client-server architecture:

  1. Server (better-auth): Handles auth logic, database ops, API routes
  2. Client (better-auth/client): Provides hooks/methods for frontend
  3. Plugins: Extend both server/client functionality

Implementation Checklist

  • Install better-auth package
  • Set environment variables (SECRET, URL)
  • Create auth server instance with database config
  • Run schema migration (npx @better-auth/cli generate)
  • Mount API handler in framework
  • Create client instance
  • Implement sign-up/sign-in UI
  • Add session management to components
  • Set up protected routes/middleware
  • Add plugins as needed (regenerate schema after)
  • Test complete auth flow
  • Configure email sending (verification/reset)
  • Enable rate limiting for production
  • Set up error handling

Reference Documentation

Core Authentication

Advanced Features

  • Advanced Features - 2FA/MFA, passkeys, magic links, organizations, rate limiting, session management

Scripts

  • scripts/better_auth_init.py - Initialize Better Auth configuration with interactive setup

Resources

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

aesthetic

FreeSummary

Design interfaces by studying reference examples, setting visual rules, and balancing appearance with usability and accessibility. The skill also guides screenshot analysis, iterative design image generation, micro interactions, and documenting design decisions in project guidelines.

  • Analyzing a reference interface
  • Setting a color and typography system
  • Refining a generated design image
mrgoonie/claudekit-skills2.2KUpdated Apr 3, 2026

ai-multimodal

FreeSummary

Use Google Gemini to analyze audio, images, videos, and PDFs, or generate and edit images. Get results such as timestamped transcripts, summaries, extracted tables, answers about media, and images made from prompts.

  • Transcribing audio with timestamps
  • Finding information in images or screenshots
  • Summarizing videos or asking about scenes
mrgoonie/claudekit-skills2.2KUpdated Apr 3, 2026

Use this skill to plan and build backend systems, from API design and authentication to database tuning, security, testing, deployment, and monitoring. It offers technology choices and practical checklists for turning requirements into production-ready services.

  • Choosing a language, framework, database, or API style
  • Designing authentication and authorization
  • Improving database queries and service performance
mrgoonie/claudekit-skills2.2KUpdated Apr 3, 2026

bunny

FreeSummary

Integrate Bunny.net services through their APIs to configure CDN pull zones, manage stored files and video, edit DNS records, and deploy edge scripts or containers. The skill also covers Shield protection, image optimization, and the credentials each service requires.

  • Setting up a CDN pull zone and purging its cache
  • Uploading or managing files in Edge Storage
  • Creating and uploading Stream videos
mrgoonie/claudekit-skills2.2KUpdated Apr 3, 2026

chrome-devtools

FreeSummary

Use Puppeteer CLI scripts to automate browser tasks and inspect web pages. The skill can navigate, click, fill forms, capture screenshots, collect page data, monitor console and network activity, and measure performance including Core Web Vitals. Results are provided as JSON.

  • Capturing a full page or selected element
  • Automating navigation and form submission
  • Collecting page content for scraping
mrgoonie/claudekit-skills2.2KUpdated Apr 3, 2026

code-review

FreeSummary

Handle code review feedback by checking its technical accuracy before making changes, and request reviews for major work. Follow verification steps so claims about passing tests or completed tasks are backed by fresh evidence.

  • Evaluating unclear or questionable review comments
  • Requesting review after a major feature or refactor
  • Reviewing work before merging a pull request
mrgoonie/claudekit-skills2.2KUpdated Apr 3, 2026

See all skills by mrgoonie

Report a problem with this skill