published fresh until

Better Auth: how do I add login without the agent hand-rolling auth?

Summary Plan authentication against the installed Better Auth version, preserve its session and CSRF safeguards, and generate the secret with openssl rand -base64 32

Not for comparing hosted auth costs and lock-in; see better-auth-or-clerk-or-authjs-for-nextjs-auth-cost-lock-in-own-postgres

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

As of November 2026, use a maintained authentication library and plan the integration before implementation. Better Auth’s create-auth skill scans the project and asks only the missing setup questions.

Do first: identify the installed auth version, framework and database, then use matching documentation as required by the best-practices skill.

The problem in plain words

Asked for "add login", an agent often invents session and token handling from scratch. That is the part most worth borrowing from a maintained library, and the part where silent mistakes (weak secrets, missing CSRF, sessions that never expire) are costly.

What Better Auth's skills do

The better-auth/skills repository includes a security skill covering rate limiting, auth secrets and CSRF protection. The repository root lists neither a README nor a licence file.

  • create-auth requires a planning phase before any code: it scans the project for framework (Next.js, SvelteKit, Nuxt, Astro, Express, Hono), database and ORM (Prisma, Drizzle, pg, Mongo), existing auth libraries (next-auth, lucia, Clerk, Supabase Auth, Firebase) and package manager, then asks the applicable initial questions together: new project or adding or migrating, framework, database, sign-in methods and features. Providers, email verification and email-provider questions can follow after the earlier choices; it skips what it can detect (planning section).
  • best-practices says to use documentation matching the Better Auth version installed in the project.
  • security covers: secret must come from config or env and placeholder secrets are rejected in production (warns under 32 characters; generate with openssl rand -base64 32), rate limiting enabled by default in production, CSRF, trusted origins, cookies and audit logging. The documented cookie defaults include SameSite=Lax and httpOnly (security skill, security docs).

Why people pick it (and counter-views)

Choose between operating an auth library and a hosted service based on your own data and operational requirements.

Related discussions: Better Auth versus Auth.js and Clerk versus BetterAuth.

Wording to give your agent

Suggested prompt: Add authentication. Do not write your own session or token handling. Use [library]. First scan the repo for framework, ORM and existing auth and tell me what you found. Ask me the planning questions, then implement. Generate the secret with openssl, keep it in the env file that is gitignored, and read the library's security docs before finishing. Verify the /api/auth/ok route and a sign-up then sign-out in a test.

Common mistakes

  • Letting the agent keep both the old and new auth libraries; stale auth-schema after adding plugins; putting the auth secret in client-exposed env vars; Drizzle setups missing drizzle.config.ts (listed in the skill's gotchas).
  • For Supabase Auth users, see the separate RLS audit thread: authentication is not authorization.

Caveats

A skill steers the agent but does not make the resulting app secure; review the diff and run the security checklist.

Sources

Started from a post by @better-auth, packaged by the editor. Original post

Subjects

More in security

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Better Auth: how do I add login without the agent hand-rolling auth?
Summary: Plan authentication against the installed Better Auth version, preserve its session and CSRF safeguards, and generate the secret with `openssl rand -base64 32`
Copy for agent
get the whatworks thread add-login-better-auth-skill-not-handrolled-auth and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread add-login-better-auth-skill-not-handrolled-auth
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks