better-auth-best-practices

Diagnose and fix Better Auth integration failures in TypeScript applications.

Updated Aug 2, 2026
One-click install
npx skills add https://github.com/leonardoacosta/skills --skill better-auth-best-practices-leonardoacosta
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: better-auth-best-practices
Source: https://github.com/leonardoacosta/skills/tree/main/t3-stack-kit/skills/better-auth-best-practices
Command: npx skills add https://github.com/leonardoacosta/skills --skill better-auth-best-practices-leonardoacosta

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Better Auth integrations fail in ways the official docs don't warn about: rate limiters firing on Vercel preview deploys and breaking e2e tests, session objects leaking internal types across package boundaries, stale plugin schemas failing at write-time, and beta dependency pins creating supply-chain risk. This Skill documents those failure modes and their fixes. ## Core Features & Use Cases - E2E Flake Diagnosis: Identifies the VERCEL_ENV vs NODE_ENV rate-limit misconfiguration that causes auth timeouts under parallel Playwright workers on preview deployments. - Session Type Safety: Enforces narrowing ctx.session into an app-owned SessionDTO before it crosses the router boundary, preventing cross-package type leaks. - Config & Schema Verification: Covers modelName vs table-name mismatches, cookie-cache behavior for custom session fields, and CLI re-generation after plugin changes. - Use Case: A Playwright suite fails with auth timeouts only on Vercel preview deploys under concurrency. This Skill pinpoints the rate limiter defaulting to NODE_ENV-based production detection and provides the VERCEL_ENV-scoped fix. ## Quick Start Review my Better Auth configuration in auth.ts and check it against the known integration gotchas before I deploy.

Frequently Asked Questions about better-auth-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why do Better Auth e2e tests fail on Vercel preview deployments?

Better Auth's rate limiter defaults to enabled when NODE_ENV is production, but Vercel sets NODE_ENV=production on every deployment including previews. Parallel Playwright workers burst past the sign-in rate cap. Fix by scoping on VERCEL_ENV === "production" instead.

How do I return the Better Auth session from a tRPC router safely?

Never return ctx.session directly, since it leaks Better Auth's internal session shape across package boundaries and breaks UI type inference on upgrades. Define an app-owned SessionDTO in the router and narrow the session before returning it.

Does Better Auth cookie cache store custom session fields?

No. Cookie cache is a read-through cache that only stores built-in session fields. Any custom fields added via session.additionalFields are re-fetched from the database or secondaryStorage on every request, which is intended behavior.

Why does Better Auth fail after adding a plugin?

Adding or removing a plugin changes the expected database schema, but the app boots fine with a stale schema and only fails on the first plugin-specific write. Re-run npx @better-auth/cli generate or migrate after every plugin change.

Should Better Auth config use the model name or table name?

Use the ORM model name, not the underlying table name. If your Prisma or Drizzle model User maps to table users, set modelName to "user". Passing the table name can fail silently in some adapter paths.

Is pinning better-auth to a beta version a risk?

Yes. A -beta.N pin for better-auth or @better-auth/* packages in a lockfile is a supply-chain risk unless it is a deliberate mid-migration pin with a tracking note. Beta APIs change without stable compatibility guarantees, so flag beta pins in review.