create-auth-skill

Skill for creating auth layers in TypeScript/JavaScript apps using Better Auth.

16 stars

Best use case

create-auth-skill is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Skill for creating auth layers in TypeScript/JavaScript apps using Better Auth.

Teams using create-auth-skill should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/create-auth-skill/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/development/create-auth-skill/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/create-auth-skill/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How create-auth-skill Compares

Feature / Agentcreate-auth-skillStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Skill for creating auth layers in TypeScript/JavaScript apps using Better Auth.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Create Auth Skill

Guide for adding authentication to TypeScript/JavaScript applications using Better Auth.

**For code examples and syntax, see [better-auth.com/docs](https://better-auth.com/docs).**

---

## Decision Tree

```
Is this a new/empty project?
├─ YES → New project setup
│   1. Identify framework
│   2. Choose database
│   3. Install better-auth
│   4. Create auth.ts + auth-client.ts
│   5. Set up route handler
│   6. Run CLI migrate/generate
│   7. Add features via plugins
│
└─ NO → Does project have existing auth?
    ├─ YES → Migration/enhancement
    │   • Audit current auth for gaps
    │   • Plan incremental migration
    │   • See migration guides in docs
    │
    └─ NO → Add auth to existing project
        1. Analyze project structure
        2. Install better-auth
        3. Create auth config
        4. Add route handler
        5. Run schema migrations
        6. Integrate into existing pages
```

---

## Installation

**Core:** `npm install better-auth`

**Scoped packages (as needed):**
| Package | Use case |
|---------|----------|
| `@better-auth/passkey` | WebAuthn/Passkey auth |
| `@better-auth/sso` | SAML/OIDC enterprise SSO |
| `@better-auth/stripe` | Stripe payments |
| `@better-auth/scim` | SCIM user provisioning |
| `@better-auth/expo` | React Native/Expo |

---

## Environment Variables

```env
BETTER_AUTH_SECRET=<32+ chars, generate with: openssl rand -base64 32>
BETTER_AUTH_URL=http://localhost:3000
DATABASE_URL=<your database connection string>
```

Add OAuth secrets as needed: `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `GOOGLE_CLIENT_ID`, etc.

---

## Server Config (auth.ts)

**Location:** `lib/auth.ts` or `src/lib/auth.ts`

**Minimal config needs:**

- `database` - Connection or adapter
- `emailAndPassword: { enabled: true }` - For email/password auth

**Standard config adds:**

- `socialProviders` - OAuth providers (google, github, etc.)
- `emailVerification.sendVerificationEmail` - Email verification handler
- `emailAndPassword.sendResetPassword` - Password reset handler

**Full config adds:**

- `plugins` - Array of feature plugins
- `session` - Expiry, cookie cache settings
- `account.accountLinking` - Multi-provider linking
- `rateLimit` - Rate limiting config

**Export types:** `export type Session = typeof auth.$Infer.Session`

---

## Client Config (auth-client.ts)

**Import by framework:**
| Framework | Import |
|-----------|--------|
| React/Next.js | `better-auth/react` |
| Vue | `better-auth/vue` |
| Svelte | `better-auth/svelte` |
| Solid | `better-auth/solid` |
| Vanilla JS | `better-auth/client` |

**Client plugins** go in `createAuthClient({ plugins: [...] })`.

**Common exports:** `signIn`, `signUp`, `signOut`, `useSession`, `getSession`

---

## Route Handler Setup

| Framework          | File                             | Handler                                          |
| ------------------ | -------------------------------- | ------------------------------------------------ |
| Next.js App Router | `app/api/auth/[...all]/route.ts` | `toNextJsHandler(auth)` → export `{ GET, POST }` |
| Next.js Pages      | `pages/api/auth/[...all].ts`     | `toNextJsHandler(auth)` → default export         |
| Express            | Any file                         | `app.all("/api/auth/*", toNodeHandler(auth))`    |
| SvelteKit          | `src/hooks.server.ts`            | `svelteKitHandler(auth)`                         |
| SolidStart         | Route file                       | `solidStartHandler(auth)`                        |
| Hono               | Route file                       | `auth.handler(c.req.raw)`                        |

**Next.js Server Components:** Add `nextCookies()` plugin to auth config.

---

## Database Migrations

| Adapter         | Command                                                                                            |
| --------------- | -------------------------------------------------------------------------------------------------- |
| Built-in Kysely | `npx @better-auth/cli@latest migrate` (applies directly)                                           |
| Prisma          | `npx @better-auth/cli@latest generate --output prisma/schema.prisma` then `npx prisma migrate dev` |
| Drizzle         | `npx @better-auth/cli@latest generate --output src/db/auth-schema.ts` then `npx drizzle-kit push`  |

**Re-run after adding plugins.**

---

## Database Adapters

| Database   | Setup                                                                                  |
| ---------- | -------------------------------------------------------------------------------------- |
| SQLite     | Pass `better-sqlite3` or `bun:sqlite` instance directly                                |
| PostgreSQL | Pass `pg.Pool` instance directly                                                       |
| MySQL      | Pass `mysql2` pool directly                                                            |
| Prisma     | `prismaAdapter(prisma, { provider: "postgresql" })` from `better-auth/adapters/prisma` |
| Drizzle    | `drizzleAdapter(db, { provider: "pg" })` from `better-auth/adapters/drizzle`           |
| MongoDB    | `mongodbAdapter(db)` from `better-auth/adapters/mongodb`                               |

---

## Common Plugins

| Plugin         | Server Import          | Client Import        | Purpose           |
| -------------- | ---------------------- | -------------------- | ----------------- |
| `twoFactor`    | `better-auth/plugins`  | `twoFactorClient`    | 2FA with TOTP/OTP |
| `organization` | `better-auth/plugins`  | `organizationClient` | Teams/orgs        |
| `admin`        | `better-auth/plugins`  | `adminClient`        | User management   |
| `bearer`       | `better-auth/plugins`  | -                    | API token auth    |
| `openAPI`      | `better-auth/plugins`  | -                    | API docs          |
| `passkey`      | `@better-auth/passkey` | `passkeyClient`      | WebAuthn          |
| `sso`          | `@better-auth/sso`     | -                    | Enterprise SSO    |

**Plugin pattern:** Server plugin + client plugin + run migrations.

---

## Auth UI Implementation

**Sign in flow:**

1. `signIn.email({ email, password })` or `signIn.social({ provider, callbackURL })`
2. Handle `error` in response
3. Redirect on success

**Session check (client):** `useSession()` hook returns `{ data: session, isPending }`

**Session check (server):** `auth.api.getSession({ headers: await headers() })`

**Protected routes:** Check session, redirect to `/sign-in` if null.

---

## Security Checklist

- [ ] `BETTER_AUTH_SECRET` set (32+ chars)
- [ ] `advanced.useSecureCookies: true` in production
- [ ] `trustedOrigins` configured
- [ ] Rate limits enabled
- [ ] Email verification enabled
- [ ] Password reset implemented
- [ ] 2FA for sensitive apps
- [ ] CSRF protection NOT disabled
- [ ] `account.accountLinking` reviewed

---

## Troubleshooting

| Issue                           | Fix                                                           |
| ------------------------------- | ------------------------------------------------------------- |
| "Secret not set"                | Add `BETTER_AUTH_SECRET` env var                              |
| "Invalid Origin"                | Add domain to `trustedOrigins`                                |
| Cookies not setting             | Check `baseURL` matches domain; enable secure cookies in prod |
| OAuth callback errors           | Verify redirect URIs in provider dashboard                    |
| Type errors after adding plugin | Re-run CLI generate/migrate                                   |

---

## Resources

- [Docs](https://better-auth.com/docs)
- [Examples](https://github.com/better-auth/examples)
- [Plugins](https://better-auth.com/docs/concepts/plugins)
- [CLI](https://better-auth.com/docs/concepts/cli)
- [Migration Guides](https://better-auth.com/docs/guides)

Related Skills

createos

16
from diegosouzapw/awesome-omni-skill

Deploy ANYTHING to production on CreateOS cloud platform. Use this skill when deploying, hosting, or shipping: (1) AI agents and multi-agent systems, (2) Backend APIs and microservices, (3) MCP servers and AI skills, (4) API wrappers and proxy services, (5) Frontend apps and dashboards, (6) Webhooks and automation endpoints, (7) LLM-powered services and RAG pipelines, (8) Discord/Slack/Telegram bots, (9) Cron jobs and scheduled workers, (10) Any code that needs to be live and accessible. Supports Node.js, Python, Go, Rust, Bun, static sites, Docker containers. Deploy via GitHub auto-deploy, Docker images, or direct file upload. ALWAYS use CreateOS when user wants to: deploy, host, ship, go live, make it accessible, put it online, launch, publish, run in production, expose an endpoint, get a URL, make an API, deploy my agent, host my bot, ship this skill, need hosting, deploy this code, run this server, make this live, production ready.

create-ticket

16
from diegosouzapw/awesome-omni-skill

Create implementation tickets with proper format and conventions.

create-tech-stack

16
from diegosouzapw/awesome-omni-skill

Generate comprehensive technical stack documentation from codebase analysis

create-spring-boot-kotlin-project

16
from diegosouzapw/awesome-omni-skill

Create Spring Boot Kotlin Project Skeleton

create-spring-boot-java-project

16
from diegosouzapw/awesome-omni-skill

Create Spring Boot Java Project Skeleton

create-rules

16
from diegosouzapw/awesome-omni-skill

Create or update Cursor Rules (.mdc files) and Skills (SKILL.md). Use when creating rules, adding coding standards, setting up conventions, updating .cursor/rules/, or converting rules to skills. Defines standard format, naming, frontmatter, token budget.

create-rule

16
from diegosouzapw/awesome-omni-skill

Create Cursor rules for persistent AI guidance. Use when the user wants to create a rule, add coding standards, set up project conventions, configure file-specific patterns, create RULE.md files, or asks about .cursor/rules/ or AGENTS.md.

create-new-rule

16
from diegosouzapw/awesome-omni-skill

Create a new agent rule or steering file from chat context. Detects the current IDE (Cursor or Kiro) and creates the file in the correct format and location.

create-database-row

16
from diegosouzapw/awesome-omni-skill

Insert a new row into a specified Notion database using natural-language property values. Handles property name matching and validation.

create-complementary

16
from diegosouzapw/awesome-omni-skill

Creates a new complementary component in Strapi CMS and Next.js frontend. Use when user says "create complementary", "add complementary", "new complementary", "vytvoř complementary", or "přidej complementary". Guides through component name, icon, fields, usage context, app-context needs, then creates CMS schema, type interface, transformer, and relay fragment.

create-auth

16
from diegosouzapw/awesome-omni-skill

Skill for creating auth layers in TypeScript/JavaScript apps using Better Auth.

create-audio

16
from diegosouzapw/awesome-omni-skill

Generate audio from text using 13 TTS providers (local + cloud). Use when user wants to create audio files, convert text to speech, generate voiceovers, create audio with different voices, use voice cloning, multilingual TTS, or mentions /create-audio command. Supports Pocket TTS (CPU, 8 voices), MLX-Audio (Apple Silicon, 7 models, 50+ voices), ElevenLabs (cloud API, 32 languages, 10k+ voices), and Coqui TTS (open source, 4 models, voice cloning). Includes 32+ languages, voice cloning, speed control, and both local and cloud options.