Create Auth Skill
Scaffold and implement authentication in TypeScript/JavaScript apps using Better Auth. Detect frameworks, configure database adapters, set up route
What Is This?
Overview
The Create Auth Skill is a structured workflow for scaffolding and implementing authentication in TypeScript and JavaScript applications using Better Auth. It covers the full setup process, from detecting your existing framework to configuring database adapters, registering route handlers, adding OAuth providers, and generating authentication UI pages. Rather than manually wiring together authentication logic from scratch, this skill provides a repeatable, opinionated approach that integrates cleanly with modern web frameworks.
Better Auth is a framework-agnostic authentication library designed for TypeScript and JavaScript projects. It supports a wide range of databases and OAuth providers, making it suitable for both simple login flows and complex multi-provider authentication systems. The Create Auth Skill acts as a practical guide for applying Better Auth correctly across different project types, reducing setup time and configuration errors.
Whether you are starting a new project or adding authentication to an existing codebase, this skill walks through each configuration step in sequence. It handles the decisions that typically slow down developers, such as which adapter to use, how to structure route handlers, and where to place auth UI components.
Who Should Use This
- Full-stack developers building TypeScript or JavaScript web applications who need a reliable authentication setup without writing boilerplate from scratch.
- Backend engineers integrating authentication into API-first projects who need route handler configuration and database adapter setup.
- Frontend developers adding login and sign-up pages to existing applications who want pre-structured UI components connected to an auth backend.
- Teams adopting Better Auth for the first time who need a consistent, repeatable process for onboarding authentication across multiple projects.
- Solo developers working on SaaS products who need OAuth provider support alongside standard email and password authentication.
- Developers migrating from other authentication libraries who want a clear framework for replacing existing auth logic with Better Auth.
Why Use It?
Problems It Solves
- Setting up authentication manually requires coordinating multiple moving parts, including session management, database schemas, and route protection. This skill provides a structured sequence that reduces the chance of missing critical steps.
- Configuring database adapters for different ORMs and database clients is often underdocumented. This skill covers adapter selection and configuration for common database setups.
- Adding OAuth providers requires correct callback URL registration, environment variable management, and provider-specific configuration. This skill standardizes that process.
- Building auth UI pages from scratch is repetitive. This skill includes patterns for generating login, sign-up, and session management pages that connect directly to the Better Auth backend.
- Framework detection ensures that route handlers are registered correctly for Next.js, Express, Hono, and other supported environments, preventing routing mismatches.
Core Highlights
- Automatic framework detection to apply the correct route handler pattern
- Database adapter configuration for popular ORMs including Prisma and Drizzle
- OAuth provider setup for Google, GitHub, and other supported providers
- Session management configuration with secure defaults
- Auth UI page scaffolding for login and sign-up flows
- Environment variable templates for secrets and provider credentials
- TypeScript-first configuration with full type safety
- Compatible with both new projects and existing codebases
How to Use It?
Basic Usage
Start by installing Better Auth and initializing the configuration file.
npm install better-auth
npx better-auth initThis generates a base auth.ts configuration file. A minimal setup looks like this:
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { prisma } from "./prisma";
export const auth = betterAuth({
database: prismaAdapter(prisma, { provider: "postgresql" }),
emailAndPassword: { enabled: true },
});Specific Scenarios
For a Next.js application, register the route handler in app/api/auth/[...all]/route.ts:
import { auth } from "@/lib/auth";
import { toNextJsHandler } from "better-auth/next-js";
export const { GET, POST } = toNextJsHandler(auth);For an Express application, mount the handler as middleware:
import express from "express";
import { toNodeHandler } from "better-auth/node";
import { auth } from "./auth";
const app = express();
app.all("/api/auth/*", toNodeHandler(auth));Real-World Examples
Adding a Google OAuth provider requires registering credentials and updating the config:
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
},Important Notes
Requirements
- Node.js 18 or higher is required for Better Auth compatibility.
- A supported database must be configured before running the auth server.
- OAuth provider credentials must be registered with each provider's developer console before use.
More Skills You Might Like
Explore similar skills to enhance your workflow
Metrics Dashboard
Define and design a product metrics dashboard with key metrics, data sources, visualization types, and alert thresholds. Use when creating a
Wp Interactivity API
Use when building or debugging WordPress Interactivity API features (data-wp-* directives, @wordpress/interactivity store/state/actions, block
vc (v1)
lark-cli docs +media-download --type whiteboard --token <whiteboardtoken> --output ./artifact-<title>/cover
Create GitHub Issues For Unmet Specification Requirements
create-github-issues-for-unmet-specification-requirements skill for design & creative
Localization Pipeline
argument-hint: "[scan|extract|validate|status|brief|cultural-review|vo-pipeline|rtl-check|freeze|qa]"
base
Interact with Lark Base spreadsheets and databases through the Lark API