Better Auth setup and best practices

Guides Better Auth configuration in TypeScript projects: version-matched docs, env vars, auth.ts, adapters, migrations, sessions and cookie cache, hooks, plugins and common gotchas. Use when changing a setting in an existing Better Auth setup.

SecurityPack: Better Auth skillslinkbetter-auth-best-practices
Author
Source
better-auth/skills/better-auth/best-practices @ 20c9e88
License
none stated

About this skill

What it does

The skill is a condensed reference for configuring Better Auth in a TypeScript project, server and client. First it pins the docs to the better-auth version in the lockfile, read through the Better Auth MCP server (get_doc, search_docs) or from better-auth.com/llms.txt; upgrade advice keeps the installed and target versions apart.

Then comes a six-step setup: install, BETTER_AUTH_SECRET and BETTER_AUTH_URL, auth.ts, a route handler, migrations (npx auth@latest migrate, or generate for Drizzle and Prisma) and a check against GET /api/auth/ok. Short notes follow on core options, database adapters, session storage (secondaryStorage, the database or a stateless cookie cache), email hooks, the advanced security flags, rate limits, hooks, plugins, client imports per framework and $Infer types. Eight gotchas close it, such as model versus table names and re-running the CLI after adding a plugin.

The folder holds only SKILL.md. npx auth@latest mcp --cursor adds the MCP server; without it the agent needs web access.

When to use it, and when not

Use it when the project runs Better Auth, or is about to, and the question is a setting: sessions, cookies, an adapter, a plugin, a hook, an upgrade.

A first setup with pages and planning questions is the job of Add authentication with Better Auth. On Neon's Managed Better Auth, plugins are switched on through Neon and the @neon/auth client takes no plugins option, so much of this does not apply.

How to run it

We do not copy this skill: the author's repository has no licence. Install it from there with the button to the source. The repository's .claude-plugin/marketplace.json defines a Claude Code plugin, auth-skills, holding this skill and create-auth: claude plugin marketplace add better-auth/skills, then claude plugin install auth-skills@better-auth-agent-skills. The skill may then appear as auth-skills:better-auth-best-practices. For another agent, copy the better-auth/best-practices folder into its skills directory.

  • Claude Code: /better-auth-best-practices, or ask for the skill by name.
  • Codex: $better-auth-best-practices.
  • Cursor: type / in the Agent chat and pick better-auth-best-practices.

Example: /better-auth-best-practices Sessions are in Redis now; keep a copy in Postgres and switch the cookie cache to jwe.

How it differs from similar skills

Add authentication with Better Auth builds auth from nothing and holds the Drizzle setup examples this skill refers to. Four skills from the pack expand what this one covers in a few lines: email and password, two-factor authentication, organizations and security hardening. Neon Auth runs Better Auth as a managed service on Neon with a fixed plugin set. No other skill in our catalog configures a self-hosted Better Auth: for that case Neon Auth only points to the Better Auth docs.

Install

This skill is not copied to the catalog: the author's repository has no licence text. Install it from there.

Open the source

Connect through AnyModel API

This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.

More from the pack Better Auth skills