better-auth-best-practices
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
Skill by dmvthrowers
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/dmvthrowers-better-auth-best-practices
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, security, productivity
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
better-auth-best-practices- Description
- Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention Better Auth, betterauth, auth.ts, or need to set up TypeScript authentication with email/password, OAuth, or plugin configuration.
- License
- Unlicense
- Instructions
- 171 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Better Auth Integration Guide
**Always consult [better-auth.com/docs](https://better-auth.com/docs) for code examples and latest API.**
---
## Setup Workflow
1. Install: `npm install better-auth`
2. Set env vars: `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL`
3. Create `auth.ts` with database + config
4. Create route handler for your framework
5. Run `npx @better-auth/cli@latest migrate`
6. Verify: call `GET /api/auth/ok` — should return `{ status: "ok" }`
---
## Quick Reference
### Environment Variables
- `BETTER_AUTH_SECRET` - Encryption secret (min 32 chars). Generate: `openssl rand -base64 32`
- `BETTER_AUTH_URL` - Base URL (e.g., `https://example.com`)
Only define `baseURL`/`secret` in config if env vars are NOT set.
### File Location
CLI looks for `auth.ts` in: `./`, `./lib`, `./utils`, or under `./src`. Use `--config` for custom path.
### CLI Commands
- `npx @better-auth/cli@latest migrate` - Apply schema (built-in adapter)
- `npx @better-auth/cli@latest generate` - Generate schema for Prisma/Drizzle
- `npx @better-auth/cli mcp --cursor` - Add MCP to AI tools
**Re-run after adding/changing plugins.**
---
## Core Config Options
| Option | Notes |
|--------|-------|
| `appName` | Optional display name |
| `baseURL` | Only if `BETTER_AUTH_URL` not set |
| `basePath` | Default `/api/auth`. Set `/` for root. |
| `secret` | Only if `BETTER_AUTH_SECRET` not set |
| `database` | Required for most features. See adapters docs. |
| `secondaryStorage` | Redis/KV for sessions & rate limits |
| `emailAndPassword` | `{ enabled: true }` to activate |
| `socialProviders` | `{ google: { clientId, clientSecret }, ... }` |
| `plugins` | Array of plugins |
| `trustedOrigins` | CSRF whitelist |
---
## Database
**Direct connections:** Pass `pg.Pool`, `mysql2` pool, `better-sqlite3`, or `bun:sqlite` instance.
**ORM adapters:** Import from `better-auth/adapters/drizzle`, `better-auth/adapters/prisma`, `better-auth/adapters/mongodb`.
**Critical:** Better Auth uses adapter model names, NOT underlying table names. If Prisma model is `User` mapping to table `users`, use `modelName: "user"` (Prisma reference), not `"users"`.
---
## Session Management
**Storage priority:**
1. If `secondaryStorage` defined → sessions go there (not DB)
2. Set `session.storeSessionInDatabase: true` to also persist to DB
3. No database + `cookieCache` → fully stateless mode
**Cookie cache strategies:**
- `compact` (default) - Base64url + HMAC. Smallest.
- `jwt` - Standard JWT. Readable but signed.
- `jwe` - Encrypted. Maximum security.
**Key options:** `session.expiresIn` (default 7 days), `session.updateAge` (refresh interval), `session.cookieCache.maxAge`, `session.cookieCache.version` (change to invalidate all sessions).
---
## User & Account Config
**User:** `user.modelName`, `user.fields` (column mapping), `user.additionalFields`, `user.changeEmail.enabled` (disabled by default), `user.deleteUser.enabled` (disabled by default).
**Account:** `account.modelName`, `account.accountLinking.enabled`, `account.storeAccountCookie` (for stateless OAuth).
**Required for registration:** `email` and `name` fields.
---
## Email Flows
- `emailVerification.sendVerificationEmail` - Must be defined for verification to work
- `emailVerification.sendOnSignUp` / `sendOnSignIn` - Auto-send triggers
- `emailAndPassword.sendResetPassword` - Password reset email handler
---
## Security
**In `advanced`:**
- `useSecureCookies` - Force HTTPS cookies
- `disableCSRFCheck` - ⚠️ Security risk
- `disableOriginCheck` - ⚠️ Security risk
- `crossSubDomainCookies.enabled` - Share cookies across subdomains
- `ipAddress.ipAddressHeaders` - Custom IP headers for proxies
- `database.generateId` - Custom ID generation or `"serial"`/`"uuid"`/`false`
**Rate limiting:** `rateLimit.enabled`, `rateLimit.window`, `rateLimit.max`, `rateLimit.storage` ("memory" | "database" | "secondary-storage").
---
## Hooks
**Endpoint hooks:** `hooks.before` / `hooks.after` - Array of `{ matcher, handler }`. Use `createAuthMiddleware`. Access `ctx.path`, `ctx.context.returned` (after), `ctx.context.session`.
**Database hooks:** `databaseHooks.user.create.before/after`, same for `session`, `account`. Useful for adding default values or post-creation actions.
**Hook context (`ctx.context`):** `session`, `secret`, `authCookies`, `password.hash()`/`verify()`, `adapter`, `internalAdapter`, `generateId()`, `tables`, `baseURL`.From dmvthrowers/yoyo-player-map, Unlicense.
More from dmvthrowers/yoyo-player-map
- 0.502score
agent-tools
dmvthrowers
Run 250+ AI apps via inference.sh CLI - image generation, video creation, LLMs, search, 3D, Twitter automation.
SkillCFreshness: C★ 1Claude Code +9 - 0.477score
skill-creator
dmvthrowers
Create new skills, modify and improve existing skills, and measure skill performance.
SkillCFreshness: C★ 1Claude Code +9 - 0.472score
find-skills
dmvthrowers
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express…
SkillCFreshness: C★ 1Claude Code +9 - 0.472score
frontend-design
dmvthrowers
Create distinctive, production-grade frontend interfaces with high design quality.
SkillCFreshness: C★ 1Claude Code +9 - 0.472score
pdf
dmvthrowers
Use this skill whenever the user wants to do anything with PDF files.
SkillCFreshness: C★ 1Claude Code +9
Signals
- Stars
- 1
- Forks
- 0
- Open issues
- 0
- Last commit (this folder)
- May 2, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- Unlicense
- Repository
- github.com/dmvthrowers/yoyo-player-map
- Website
- yoyo-player-map.vercel.app
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
- 0.736score
better-auth-best-practices
better-auth
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillBFreshness: B★ 225Claude Code +9 - 0.336score
better-auth-best-practices
omarauf
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillAFreshness: AClaude Code +9 - 0.312score
better-auth-best-practices
AI-Degen-69
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillBFreshness: BClaude Code +9 - 0.282score
better-auth-best-practices
Pegarose
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillCFreshness: CClaude Code +9 - 0.282score
better-auth-best-practices
chroniicallydiistracted
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillCFreshness: CClaude Code +9 - 0.282score
better-auth-best-practices
Pegarose
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillCFreshness: CClaude Code +9 - 0.282score
better-auth-best-practices
relvorlabs
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillCFreshness: CClaude Code +9 - 0.263score
better-auth-best-practices
wlue
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillDFreshness: D★ 2Claude Code +9 - 0.263score
better-auth-best-practices
Lua2147
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillDFreshness: D★ 2Claude Code +9 - 0.243score
better-auth-best-practices
sidjamyl
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillDFreshness: DClaude Code +9 - 0.243score
better-auth-best-practices
sidjamyl
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillDFreshness: DClaude Code +9 - 0.243score
better-auth-best-practices
tusosos
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables.
SkillDFreshness: DClaude Code +9
More from dmvthrowers
- 0.502score
agent-tools
dmvthrowers
Run 250+ AI apps via inference.sh CLI - image generation, video creation, LLMs, search, 3D, Twitter automation.
SkillCFreshness: C★ 1Claude Code +9 - 0.477score
skill-creator
dmvthrowers
Create new skills, modify and improve existing skills, and measure skill performance.
SkillCFreshness: C★ 1Claude Code +9 - 0.472score
find-skills
dmvthrowers
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express…
SkillCFreshness: C★ 1Claude Code +9 - 0.472score
frontend-design
dmvthrowers
Create distinctive, production-grade frontend interfaces with high design quality.
SkillCFreshness: C★ 1Claude Code +9 - 0.472score
pdf
dmvthrowers
Use this skill whenever the user wants to do anything with PDF files.
SkillCFreshness: C★ 1Claude Code +9
Cite this page
better-auth-best-practices skill. Agent Mart. https://agentmart.dev/skills/dmvthrowers-better-auth-best-practices (last updated 2026-10-24)