[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72Y7RBEW5C9F741A8KJM6VW":3,"skill-same:01M72Y7RBEW5C9F741A8KJM6VW":93},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":6,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M72Y7RBEW5C9F741A8KJM6VW","better-auth",null,"Better Auth — framework-agnostic TypeScript authentication & authorization library.\nCovers setup, email\u002Fpassword, social OAuth (40+ providers), passkeys, magic links,\n2FA, organizations, sessions, plugins, admin, hooks, and security hardening.\nUse when implementing auth with Better Auth: configuring auth instances, adding\nproviders, setting up database adapters (Prisma, Drizzle, PostgreSQL, MySQL, SQLite,\nMongoDB), integrating with frameworks (Next.js, Nuxt, SvelteKit, Astro, Hono, Express,\nElysia, Fastify, Expo), managing sessions, or extending with plugins.","marcioaltoe\u002Fskills","marcioaltoe","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1562865?v=4","01M72Y3750J2CG00P0H2AHDRSZ","Marcio Altoé","01M72Y37642F46H36R4E4S7BNA",0,"MIT","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: better-auth\ndescription: |\n  Better Auth — framework-agnostic TypeScript authentication & authorization library.\n  Covers setup, email\u002Fpassword, social OAuth (40+ providers), passkeys, magic links,\n  2FA, organizations, sessions, plugins, admin, hooks, and security hardening.\n  Use when implementing auth with Better Auth: configuring auth instances, adding\n  providers, setting up database adapters (Prisma, Drizzle, PostgreSQL, MySQL, SQLite,\n  MongoDB), integrating with frameworks (Next.js, Nuxt, SvelteKit, Astro, Hono, Express,\n  Elysia, Fastify, Expo), managing sessions, or extending with plugins.\n---\n\n# Better Auth\n\nFramework-agnostic TypeScript auth library. Plugin-based architecture, 40+ OAuth providers, 18+ framework integrations.\n\n## Quick Start\n\n### Install\n\n```bash\nnpm install better-auth\n```\n\nScoped packages (as needed):\n\n| Package | Use case |\n|---------|----------|\n| `@better-auth\u002Fpasskey` | WebAuthn\u002FPasskey auth |\n| `@better-auth\u002Fsso` | SAML\u002FOIDC enterprise SSO |\n| `@better-auth\u002Fstripe` | Stripe payments |\n| `@better-auth\u002Fexpo` | React Native\u002FExpo |\n\n### Environment Variables\n\n```env\nBETTER_AUTH_SECRET=\u003C32+ chars, generate: openssl rand -base64 32>\nBETTER_AUTH_URL=http:\u002F\u002Flocalhost:3000\nDATABASE_URL=\u003Cconnection string>\n```\n\n### Server Config (`lib\u002Fauth.ts`)\n\n```ts\nimport { betterAuth } from \"better-auth\";\n\nexport const auth = betterAuth({\n  database: process.env.DATABASE_URL,  \u002F\u002F or adapter instance\n  emailAndPassword: { enabled: true },\n  socialProviders: {\n    google: {\n      clientId: process.env.GOOGLE_CLIENT_ID!,\n      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,\n    },\n  },\n  plugins: [], \u002F\u002F add plugins here\n});\n\nexport type Session = typeof auth.$Infer.Session;\n```\n\n### Client Config (`lib\u002Fauth-client.ts`)\n\n```ts\nimport { createAuthClient } from \"better-auth\u002Freact\"; \u002F\u002F or \u002Fvue, \u002Fsvelte, \u002Fsolid, \u002Fclient\n\nexport const authClient = createAuthClient({\n  plugins: [], \u002F\u002F add client plugins here\n});\n```\n\n### Route Handler\n\n| Framework | File | Handler |\n|-----------|------|---------|\n| Next.js App Router | `app\u002Fapi\u002Fauth\u002F[...all]\u002Froute.ts` | `toNextJsHandler(auth)` → export `{ GET, POST }` |\n| Next.js Pages | `pages\u002Fapi\u002Fauth\u002F[...all].ts` | `toNextJsHandler(auth)` → default export |\n| Express | any | `app.all(\"\u002Fapi\u002Fauth\u002F*splat\", toNodeHandler(auth))` |\n| Hono | route | `app.on([\"POST\",\"GET\"], \"\u002Fapi\u002Fauth\u002F**\", (c) => auth.handler(c.req.raw))` |\n| SvelteKit | `hooks.server.ts` | `svelteKitHandler({ auth, event })` |\n| Astro | `pages\u002Fapi\u002Fauth\u002F[...all].ts` | `toAstroHandler(auth)` |\n| Elysia | plugin | `new Elysia().mount(auth.handler)` |\n\nSee [references\u002Fframework-integrations.md](references\u002Fframework-integrations.md) for all frameworks.\n\n### CLI Commands\n\n```bash\nnpx @better-auth\u002Fcli@latest migrate          # Apply schema (built-in adapter)\nnpx @better-auth\u002Fcli@latest generate          # Generate for Prisma\u002FDrizzle\nnpx @better-auth\u002Fcli@latest generate --output prisma\u002Fschema.prisma\nnpx @better-auth\u002Fcli@latest generate --output src\u002Fdb\u002Fauth-schema.ts\n```\n\n**Re-run after adding\u002Fchanging plugins.**\n\n## Core Concepts\n\n- **Server instance** (`auth`): handles all auth logic, DB, sessions\n- **Client instance** (`authClient`): framework-specific hooks (`useSession`, `signIn`, `signUp`, `signOut`)\n- **Plugins**: extend both server and client — add endpoints, DB tables, hooks\n- **Type inference**: `auth.$Infer.Session`, `auth.$Infer.Session.user` for full type safety\n- For separate client\u002Fserver projects: `createAuthClient\u003Ctypeof auth>()`\n\n## Authentication Methods\n\n| Method | Package | Config\u002FPlugin | Reference |\n|--------|---------|---------------|-----------|\n| Email\u002FPassword | built-in | `emailAndPassword: { enabled: true }` | [authentication.md](references\u002Fauthentication.md) |\n| Social OAuth | built-in | `socialProviders: { google: {...} }` | [authentication.md](references\u002Fauthentication.md) |\n| Magic Link | built-in | `magicLink()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Passkey | `@better-auth\u002Fpasskey` | `passkey()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Username | built-in | `username()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Email OTP | built-in | `emailOtp()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Phone Number | built-in | `phoneNumber()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Anonymous | built-in | `anonymous()` plugin | [authentication.md](references\u002Fauthentication.md) |\n\n## Plugin Quick Reference\n\nImport from dedicated paths for tree-shaking: `import { twoFactor } from \"better-auth\u002Fplugins\u002Ftwo-factor\"` NOT `from \"better-auth\u002Fplugins\"`.\n\n| Plugin | Server Import | Client Import | Purpose |\n|--------|---------------|---------------|---------|\n| `twoFactor` | `better-auth\u002Fplugins\u002Ftwo-factor` | `twoFactorClient` | TOTP, OTP, backup codes |\n| `organization` | `better-auth\u002Fplugins\u002Forganization` | `organizationClient` | Multi-tenant orgs, teams, RBAC |\n| `admin` | `better-auth\u002Fplugins\u002Fadmin` | `adminClient` | User management, impersonation |\n| `passkey` | `@better-auth\u002Fpasskey` | `passkeyClient` | WebAuthn\u002FFIDO2 |\n| `magicLink` | `better-auth\u002Fplugins\u002Fmagic-link` | `magicLinkClient` | Passwordless email links |\n| `emailOtp` | `better-auth\u002Fplugins\u002Femail-otp` | `emailOtpClient` | Email one-time passwords |\n| `username` | `better-auth\u002Fplugins\u002Fusername` | `usernameClient` | Username-based auth |\n| `phoneNumber` | `better-auth\u002Fplugins\u002Fphone-number` | `phoneNumberClient` | Phone-based auth |\n| `anonymous` | `better-auth\u002Fplugins\u002Fanonymous` | `anonymousClient` | Guest sessions |\n| `apiKey` | `better-auth\u002Fplugins\u002Fapi-key` | `apiKeyClient` | API key management |\n| `bearer` | `better-auth\u002Fplugins\u002Fbearer` | — | Bearer token auth |\n| `jwt` | `better-auth\u002Fplugins\u002Fjwt` | `jwtClient` | JWT tokens |\n| `multiSession` | `better-auth\u002Fplugins\u002Fmulti-session` | `multiSessionClient` | Multiple active sessions |\n| `oauthProvider` | `better-auth\u002Fplugins\u002Foauth-provider` | — | Become OAuth provider |\n| `oidcProvider` | `better-auth\u002Fplugins\u002Foidc-provider` | — | Become OIDC provider |\n| `sso` | `@better-auth\u002Fsso` | `ssoClient` | SAML\u002FOIDC enterprise SSO |\n| `openAPI` | `better-auth\u002Fplugins\u002Fopen-api` | — | API documentation |\n| `customSession` | `better-auth\u002Fplugins\u002Fcustom-session` | — | Extend session data |\n| `genericOAuth` | `better-auth\u002Fplugins\u002Fgeneric-oauth` | `genericOAuthClient` | Custom OAuth providers |\n| `oneTap` | `better-auth\u002Fplugins\u002Fone-tap` | `oneTapClient` | Google One Tap |\n\nPattern: server plugin in `auth({ plugins: [...] })` + client plugin in `createAuthClient({ plugins: [...] })` + re-run CLI migrations.\n\nSee [references\u002Fplugins.md](references\u002Fplugins.md) for detailed usage and custom plugin creation.\n\n## Database Setup\n\n| Adapter | Setup |\n|---------|-------|\n| SQLite | Pass `better-sqlite3` or `bun:sqlite` instance |\n| PostgreSQL | Pass `pg.Pool` instance |\n| MySQL | Pass `mysql2` pool |\n| Prisma | `prismaAdapter(prisma, { provider: \"postgresql\" })` from `better-auth\u002Fadapters\u002Fprisma` |\n| Drizzle | `drizzleAdapter(db, { provider: \"pg\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| MongoDB | `mongodbAdapter(db)` from `better-auth\u002Fadapters\u002Fmongodb` |\n| Connection string | `database: process.env.DATABASE_URL` (uses built-in Kysely) |\n\n**Critical:** Config uses ORM model name, NOT DB table name. Prisma model `User` mapping to table `users` → use `modelName: \"user\"`.\n\nCore schema tables: `user`, `session`, `account`, `verification`. Plugins add their own tables.\n\nSee [references\u002Fsetup.md](references\u002Fsetup.md) for full database setup details.\n\n## Session Management\n\nKey options:\n\n```ts\nsession: {\n  expiresIn: 60 * 60 * 24 * 7,  \u002F\u002F 7 days (default)\n  updateAge: 60 * 60 * 24,       \u002F\u002F refresh every 24h (default)\n  freshAge: 60 * 60 * 24,        \u002F\u002F require re-auth after 24h for sensitive ops\n  cookieCache: {\n    enabled: true,\n    maxAge: 300,                  \u002F\u002F 5 min\n    strategy: \"compact\",          \u002F\u002F \"compact\" | \"jwt\" | \"jwe\"\n  },\n}\n```\n\n- **`secondaryStorage`** (Redis\u002FKV): sessions go there by default, not DB\n- **Stateless mode**: no DB + cookieCache = session in cookie only\n- **`customSession` plugin**: extend session with custom fields\n\nSee [references\u002Fsessions.md](references\u002Fsessions.md) for full session management details.\n\n## Security Checklist\n\n| DO | DON'T |\n|----|-------|\n| Use 32+ char secret with high entropy | Commit secrets to version control |\n| Set `baseURL` with HTTPS in production | Disable CSRF check (`disableCSRFCheck`) |\n| Configure `trustedOrigins` for all frontends | Disable origin check |\n| Enable rate limiting (on by default in prod) | Use `\"memory\"` rate limit storage in serverless |\n| Configure `backgroundTasks.handler` on serverless | Skip email verification setup |\n| Use `\"jwe\"` cookie cache for sensitive session data | Store OAuth tokens unencrypted if used for API calls |\n| Set `revokeSessionsOnPasswordReset: true` | Return specific error messages (\"user not found\") |\n\nSee [references\u002Fsecurity.md](references\u002Fsecurity.md) for complete security hardening guide.\n\n## Common Gotchas\n\n1. **Model vs table name** — config uses ORM model name, not DB table name\n2. **Plugin schema** — re-run CLI after adding\u002Fchanging plugins\n3. **Secondary storage** — sessions go there by default, not DB. Set `session.storeSessionInDatabase: true` to persist both\n4. **Cookie cache** — custom session fields NOT cached, always re-fetched from DB\n5. **Callback URLs** — always use absolute URLs with origin (not relative paths)\n6. **Express v5** — use `\"\u002Fapi\u002Fauth\u002F*splat\"` not `\"\u002Fapi\u002Fauth\u002F*\"` for catch-all routes\n7. **Next.js RSC** — add `nextCookies()` plugin to auth config for server component session access\n\n## Troubleshooting\n\n| Issue | Fix |\n|-------|-----|\n| \"Secret not set\" | Add `BETTER_AUTH_SECRET` env var |\n| \"Invalid Origin\" | Add domain to `trustedOrigins` |\n| Cookies not setting | Check `baseURL` matches domain; enable secure cookies in prod |\n| OAuth callback errors | Verify redirect URIs in provider dashboard match exactly |\n| Type errors after adding plugin | Re-run CLI generate\u002Fmigrate |\n| Session null in RSC | Add `nextCookies()` plugin |\n| 2FA redirect not working | Add `twoFactorClient` with `onTwoFactorRedirect` to client |\n\n## Reference Index\n\n| File | When to read |\n|------|-------------|\n| [setup.md](references\u002Fsetup.md) | Setting up new project, configuring DB, route handlers |\n| [authentication.md](references\u002Fauthentication.md) | Implementing any auth method (email, social, passkey, magic link, etc.) |\n| [sessions.md](references\u002Fsessions.md) | Configuring session expiry, caching, stateless mode, secondary storage |\n| [security.md](references\u002Fsecurity.md) | Hardening for production — rate limiting, CSRF, cookies, OAuth security |\n| [plugins.md](references\u002Fplugins.md) | Using or creating plugins, plugin catalog |\n| [framework-integrations.md](references\u002Fframework-integrations.md) | Framework-specific setup (Next.js, Nuxt, SvelteKit, Hono, Express, etc.) |\n| [two-factor.md](references\u002Ftwo-factor.md) | Implementing 2FA (TOTP, OTP, backup codes, trusted devices) |\n| [organizations.md](references\u002Forganizations.md) | Multi-tenant orgs, teams, invitations, RBAC |\n| [admin.md](references\u002Fadmin.md) | User management, roles, banning, impersonation |\n| [hooks-and-middleware.md](references\u002Fhooks-and-middleware.md) | Custom logic via before\u002Fafter hooks, DB hooks, middleware |\n","# Better Auth\n\nFramework-agnostic TypeScript auth library. Plugin-based architecture, 40+ OAuth providers, 18+ framework integrations.\n\n## Quick Start\n\n### Install\n\n```bash\nnpm install better-auth\n```\n\nScoped packages (as needed):\n\n| Package | Use case |\n|---------|----------|\n| `@better-auth\u002Fpasskey` | WebAuthn\u002FPasskey auth |\n| `@better-auth\u002Fsso` | SAML\u002FOIDC enterprise SSO |\n| `@better-auth\u002Fstripe` | Stripe payments |\n| `@better-auth\u002Fexpo` | React Native\u002FExpo |\n\n### Environment Variables\n\n```env\nBETTER_AUTH_SECRET=\u003C32+ chars, generate: openssl rand -base64 32>\nBETTER_AUTH_URL=http:\u002F\u002Flocalhost:3000\nDATABASE_URL=\u003Cconnection string>\n```\n\n### Server Config (`lib\u002Fauth.ts`)\n\n```ts\nimport { betterAuth } from \"better-auth\";\n\nexport const auth = betterAuth({\n  database: process.env.DATABASE_URL,  \u002F\u002F or adapter instance\n  emailAndPassword: { enabled: true },\n  socialProviders: {\n    google: {\n      clientId: process.env.GOOGLE_CLIENT_ID!,\n      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,\n    },\n  },\n  plugins: [], \u002F\u002F add plugins here\n});\n\nexport type Session = typeof auth.$Infer.Session;\n```\n\n### Client Config (`lib\u002Fauth-client.ts`)\n\n```ts\nimport { createAuthClient } from \"better-auth\u002Freact\"; \u002F\u002F or \u002Fvue, \u002Fsvelte, \u002Fsolid, \u002Fclient\n\nexport const authClient = createAuthClient({\n  plugins: [], \u002F\u002F add client plugins here\n});\n```\n\n### Route Handler\n\n| Framework | File | Handler |\n|-----------|------|---------|\n| Next.js App Router | `app\u002Fapi\u002Fauth\u002F[...all]\u002Froute.ts` | `toNextJsHandler(auth)` → export `{ GET, POST }` |\n| Next.js Pages | `pages\u002Fapi\u002Fauth\u002F[...all].ts` | `toNextJsHandler(auth)` → default export |\n| Express | any | `app.all(\"\u002Fapi\u002Fauth\u002F*splat\", toNodeHandler(auth))` |\n| Hono | route | `app.on([\"POST\",\"GET\"], \"\u002Fapi\u002Fauth\u002F**\", (c) => auth.handler(c.req.raw))` |\n| SvelteKit | `hooks.server.ts` | `svelteKitHandler({ auth, event })` |\n| Astro | `pages\u002Fapi\u002Fauth\u002F[...all].ts` | `toAstroHandler(auth)` |\n| Elysia | plugin | `new Elysia().mount(auth.handler)` |\n\nSee [references\u002Fframework-integrations.md](references\u002Fframework-integrations.md) for all frameworks.\n\n### CLI Commands\n\n```bash\nnpx @better-auth\u002Fcli@latest migrate          # Apply schema (built-in adapter)\nnpx @better-auth\u002Fcli@latest generate          # Generate for Prisma\u002FDrizzle\nnpx @better-auth\u002Fcli@latest generate --output prisma\u002Fschema.prisma\nnpx @better-auth\u002Fcli@latest generate --output src\u002Fdb\u002Fauth-schema.ts\n```\n\n**Re-run after adding\u002Fchanging plugins.**\n\n## Core Concepts\n\n- **Server instance** (`auth`): handles all auth logic, DB, sessions\n- **Client instance** (`authClient`): framework-specific hooks (`useSession`, `signIn`, `signUp`, `signOut`)\n- **Plugins**: extend both server and client — add endpoints, DB tables, hooks\n- **Type inference**: `auth.$Infer.Session`, `auth.$Infer.Session.user` for full type safety\n- For separate client\u002Fserver projects: `createAuthClient\u003Ctypeof auth>()`\n\n## Authentication Methods\n\n| Method | Package | Config\u002FPlugin | Reference |\n|--------|---------|---------------|-----------|\n| Email\u002FPassword | built-in | `emailAndPassword: { enabled: true }` | [authentication.md](references\u002Fauthentication.md) |\n| Social OAuth | built-in | `socialProviders: { google: {...} }` | [authentication.md](references\u002Fauthentication.md) |\n| Magic Link | built-in | `magicLink()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Passkey | `@better-auth\u002Fpasskey` | `passkey()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Username | built-in | `username()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Email OTP | built-in | `emailOtp()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Phone Number | built-in | `phoneNumber()` plugin | [authentication.md](references\u002Fauthentication.md) |\n| Anonymous | built-in | `anonymous()` plugin | [authentication.md](references\u002Fauthentication.md) |\n\n## Plugin Quick Reference\n\nImport from dedicated paths for tree-shaking: `import { twoFactor } from \"better-auth\u002Fplugins\u002Ftwo-factor\"` NOT `from \"better-auth\u002Fplugins\"`.\n\n| Plugin | Server Import | Client Import | Purpose |\n|--------|---------------|---------------|---------|\n| `twoFactor` | `better-auth\u002Fplugins\u002Ftwo-factor` | `twoFactorClient` | TOTP, OTP, backup codes |\n| `organization` | `better-auth\u002Fplugins\u002Forganization` | `organizationClient` | Multi-tenant orgs, teams, RBAC |\n| `admin` | `better-auth\u002Fplugins\u002Fadmin` | `adminClient` | User management, impersonation |\n| `passkey` | `@better-auth\u002Fpasskey` | `passkeyClient` | WebAuthn\u002FFIDO2 |\n| `magicLink` | `better-auth\u002Fplugins\u002Fmagic-link` | `magicLinkClient` | Passwordless email links |\n| `emailOtp` | `better-auth\u002Fplugins\u002Femail-otp` | `emailOtpClient` | Email one-time passwords |\n| `username` | `better-auth\u002Fplugins\u002Fusername` | `usernameClient` | Username-based auth |\n| `phoneNumber` | `better-auth\u002Fplugins\u002Fphone-number` | `phoneNumberClient` | Phone-based auth |\n| `anonymous` | `better-auth\u002Fplugins\u002Fanonymous` | `anonymousClient` | Guest sessions |\n| `apiKey` | `better-auth\u002Fplugins\u002Fapi-key` | `apiKeyClient` | API key management |\n| `bearer` | `better-auth\u002Fplugins\u002Fbearer` | — | Bearer token auth |\n| `jwt` | `better-auth\u002Fplugins\u002Fjwt` | `jwtClient` | JWT tokens |\n| `multiSession` | `better-auth\u002Fplugins\u002Fmulti-session` | `multiSessionClient` | Multiple active sessions |\n| `oauthProvider` | `better-auth\u002Fplugins\u002Foauth-provider` | — | Become OAuth provider |\n| `oidcProvider` | `better-auth\u002Fplugins\u002Foidc-provider` | — | Become OIDC provider |\n| `sso` | `@better-auth\u002Fsso` | `ssoClient` | SAML\u002FOIDC enterprise SSO |\n| `openAPI` | `better-auth\u002Fplugins\u002Fopen-api` | — | API documentation |\n| `customSession` | `better-auth\u002Fplugins\u002Fcustom-session` | — | Extend session data |\n| `genericOAuth` | `better-auth\u002Fplugins\u002Fgeneric-oauth` | `genericOAuthClient` | Custom OAuth providers |\n| `oneTap` | `better-auth\u002Fplugins\u002Fone-tap` | `oneTapClient` | Google One Tap |\n\nPattern: server plugin in `auth({ plugins: [...] })` + client plugin in `createAuthClient({ plugins: [...] })` + re-run CLI migrations.\n\nSee [references\u002Fplugins.md](references\u002Fplugins.md) for detailed usage and custom plugin creation.\n\n## Database Setup\n\n| Adapter | Setup |\n|---------|-------|\n| SQLite | Pass `better-sqlite3` or `bun:sqlite` instance |\n| PostgreSQL | Pass `pg.Pool` instance |\n| MySQL | Pass `mysql2` pool |\n| Prisma | `prismaAdapter(prisma, { provider: \"postgresql\" })` from `better-auth\u002Fadapters\u002Fprisma` |\n| Drizzle | `drizzleAdapter(db, { provider: \"pg\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| MongoDB | `mongodbAdapter(db)` from `better-auth\u002Fadapters\u002Fmongodb` |\n| Connection string | `database: process.env.DATABASE_URL` (uses built-in Kysely) |\n\n**Critical:** Config uses ORM model name, NOT DB table name. Prisma model `User` mapping to table `users` → use `modelName: \"user\"`.\n\nCore schema tables: `user`, `session`, `account`, `verification`. Plugins add their own tables.\n\nSee [references\u002Fsetup.md](references\u002Fsetup.md) for full database setup details.\n\n## Session Management\n\nKey options:\n\n```ts\nsession: {\n  expiresIn: 60 * 60 * 24 * 7,  \u002F\u002F 7 days (default)\n  updateAge: 60 * 60 * 24,       \u002F\u002F refresh every 24h (default)\n  freshAge: 60 * 60 * 24,        \u002F\u002F require re-auth after 24h for sensitive ops\n  cookieCache: {\n    enabled: true,\n    maxAge: 300,                  \u002F\u002F 5 min\n    strategy: \"compact\",          \u002F\u002F \"compact\" | \"jwt\" | \"jwe\"\n  },\n}\n```\n\n- **`secondaryStorage`** (Redis\u002FKV): sessions go there by default, not DB\n- **Stateless mode**: no DB + cookieCache = session in cookie only\n- **`customSession` plugin**: extend session with custom fields\n\nSee [references\u002Fsessions.md](references\u002Fsessions.md) for full session management details.\n\n## Security Checklist\n\n| DO | DON'T |\n|----|-------|\n| Use 32+ char secret with high entropy | Commit secrets to version control |\n| Set `baseURL` with HTTPS in production | Disable CSRF check (`disableCSRFCheck`) |\n| Configure `trustedOrigins` for all frontends | Disable origin check |\n| Enable rate limiting (on by default in prod) | Use `\"memory\"` rate limit storage in serverless |\n| Configure `backgroundTasks.handler` on serverless | Skip email verification setup |\n| Use `\"jwe\"` cookie cache for sensitive session data | Store OAuth tokens unencrypted if used for API calls |\n| Set `revokeSessionsOnPasswordReset: true` | Return specific error messages (\"user not found\") |\n\nSee [references\u002Fsecurity.md](references\u002Fsecurity.md) for complete security hardening guide.\n\n## Common Gotchas\n\n1. **Model vs table name** — config uses ORM model name, not DB table name\n2. **Plugin schema** — re-run CLI after adding\u002Fchanging plugins\n3. **Secondary storage** — sessions go there by default, not DB. Set `session.storeSessionInDatabase: true` to persist both\n4. **Cookie cache** — custom session fields NOT cached, always re-fetched from DB\n5. **Callback URLs** — always use absolute URLs with origin (not relative paths)\n6. **Express v5** — use `\"\u002Fapi\u002Fauth\u002F*splat\"` not `\"\u002Fapi\u002Fauth\u002F*\"` for catch-all routes\n7. **Next.js RSC** — add `nextCookies()` plugin to auth config for server component session access\n\n## Troubleshooting\n\n| Issue | Fix |\n|-------|-----|\n| \"Secret not set\" | Add `BETTER_AUTH_SECRET` env var |\n| \"Invalid Origin\" | Add domain to `trustedOrigins` |\n| Cookies not setting | Check `baseURL` matches domain; enable secure cookies in prod |\n| OAuth callback errors | Verify redirect URIs in provider dashboard match exactly |\n| Type errors after adding plugin | Re-run CLI generate\u002Fmigrate |\n| Session null in RSC | Add `nextCookies()` plugin |\n| 2FA redirect not working | Add `twoFactorClient` with `onTwoFactorRedirect` to client |\n\n## Reference Index\n\n| File | When to read |\n|------|-------------|\n| [setup.md](references\u002Fsetup.md) | Setting up new project, configuring DB, route handlers |\n| [authentication.md](references\u002Fauthentication.md) | Implementing any auth method (email, social, passkey, magic link, etc.) |\n| [sessions.md](references\u002Fsessions.md) | Configuring session expiry, caching, stateless mode, secondary storage |\n| [security.md](references\u002Fsecurity.md) | Hardening for production — rate limiting, CSRF, cookies, OAuth security |\n| [plugins.md](references\u002Fplugins.md) | Using or creating plugins, plugin catalog |\n| [framework-integrations.md](references\u002Fframework-integrations.md) | Framework-specific setup (Next.js, Nuxt, SvelteKit, Hono, Express, etc.) |\n| [two-factor.md](references\u002Ftwo-factor.md) | Implementing 2FA (TOTP, OTP, backup codes, trusted devices) |\n| [organizations.md](references\u002Forganizations.md) | Multi-tenant orgs, teams, invitations, RBAC |\n| [admin.md](references\u002Fadmin.md) | User management, roles, banning, impersonation |\n| [hooks-and-middleware.md](references\u002Fhooks-and-middleware.md) | Custom logic via before\u002Fafter hooks, DB hooks, middleware |\n",{"name":5,"description":7},"main","dea450cfd9df78b5cf721964ef178a75cea55cbb","skills\u002F05-implementation-loop\u002Fbetter-auth",2,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills","https:\u002F\u002Fmarcioaltoe.github.io\u002Fskills\u002F","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe","Senior Software Engineer · Backend, Systems & AI","2026-11-14 18:29:56",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add marcioaltoe\u002Fskills --skill better-auth",{"tool":39,"command":40},"bunx","bunx skills add marcioaltoe\u002Fskills --skill better-auth",{"tool":42,"command":43},"pnpm","pnpm dlx skills add marcioaltoe\u002Fskills --skill better-auth","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002FSKILL.md",true,[47,53,57,61,65,69,73,77,81,85,89],{"path":48,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":51,"sourceHtmlUrl":52},"agents\u002Fopenai.yaml","REFERENCE","参考文档",205,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Fagents\u002Fopenai.yaml",{"path":54,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":55,"sourceHtmlUrl":56},"references\u002Fadmin.md",4121,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fadmin.md",{"path":58,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":59,"sourceHtmlUrl":60},"references\u002Fauthentication.md",9793,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fauthentication.md",{"path":62,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":63,"sourceHtmlUrl":64},"references\u002Fframework-integrations.md",11016,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fframework-integrations.md",{"path":66,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":67,"sourceHtmlUrl":68},"references\u002Fhooks-and-middleware.md",6050,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fhooks-and-middleware.md",{"path":70,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":71,"sourceHtmlUrl":72},"references\u002Forganizations.md",7166,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Forganizations.md",{"path":74,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":75,"sourceHtmlUrl":76},"references\u002Fplugins.md",7111,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fplugins.md",{"path":78,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":79,"sourceHtmlUrl":80},"references\u002Fsecurity.md",7976,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fsecurity.md",{"path":82,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":83,"sourceHtmlUrl":84},"references\u002Fsessions.md",5137,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fsessions.md",{"path":86,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":87,"sourceHtmlUrl":88},"references\u002Fsetup.md",9193,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Fsetup.md",{"path":90,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":91,"sourceHtmlUrl":92},"references\u002Ftwo-factor.md",6101,"https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F05-implementation-loop\u002Fbetter-auth\u002Freferences\u002Ftwo-factor.md",[94,102,109,116,123,130],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":101},"01M72YNVSF4JTTQG3YTR9QNT4Z","startup-validator","Comprehensive startup idea validation and market analysis tool. Use when users need to evaluate a startup idea, assess market fit, analyze competition, validate problem-solution fit, or determine market positioning. Triggers include requests to \"validate my startup idea\", \"analyze market opportunity\", \"check if there's demand for\", \"research competition for\", \"evaluate business idea\", or \"see if my idea is viable\". Provides data-driven analysis using web search, market frameworks, competitive research, and positioning recommendations.","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F10-marketing\u002Fstartup-validator\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":101},"01M72YNN34B4MYKEX1X6BB1NS1","positioning-icp","When the user wants to define their ideal customer profile, position an AI product, build messaging architecture, or validate product-market fit. Also use when the user mentions 'ICP,' 'ideal customer profile,' 'positioning,' 'PMF,' 'product-market fit,' 'messaging,' 'buyer persona,' 'enrichment signals,' 'market positioning,' or 'competitive positioning.' This skill covers market positioning, ICP definition, messaging architecture, and PMF validation for AI-native products. Do NOT use for technical implementation, code review, or software architecture.","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F10-marketing\u002Fpositioning-icp\u002FSKILL.md",[],[],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":101},"01M72YNG8XJ4RHRB5DQMCY9C1N","copywriting","When the user wants to write or rewrite page copy (homepage, landing, pricing, feature), or asks which headline, promise, or message to lead with. Diagnoses the input first (blank brief, real voice, or point edit) and changes only what it calls for. Claims must be supportable; a declined claim names the evidence that would unlock it. No AI tells like 'it's not X, it's Y' or 'no X, no Y, no Z'. For editing, see copy-editing. For emails, see emails. For the offer, see offers.","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F10-marketing\u002Fcopywriting\u002FSKILL.md",[],[],{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":101},"01M72YNBF4JMQ4VCFHTW0WS6SD","business-storyteller","Transforms technical work into persuasive business-language documents for non-technical stakeholders, including internal announcements, approval proposals, incident explainers, technical-debt cases, product explainers, and investor or partner memos. Use when the user asks to present technical work to the company, explain software to business teams, write a business case, make an approval document, or convert a technical artifact into stakeholder communication in the requested language. Do not use for READMEs, specs, ADRs, external marketing pages, or customer-facing sales copy.","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F10-marketing\u002Fbusiness-storyteller\u002FSKILL.md",[],[],{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":101},"01M72YN8NQ6QR0GHX2A8YW2K4T","brand-storytelling","Help users craft compelling brand narratives. Use when someone is defining brand strategy, writing company positioning, creating pitch narratives, developing messaging frameworks, or trying to make their company story more memorable.","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F10-marketing\u002Fbrand-storytelling\u002FSKILL.md",[],[],{"skillNo":131,"name":132,"nameZh":6,"description":133,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":134,"licenseFileUrl":135,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":101},"01M72YN3CJH7CKPF4AXNY79Q9S","skill-creator","Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F09-learning-loop\u002Fskill-creator\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fmarcioaltoe\u002Fskills\u002Fblob\u002Fmain\u002Fskills\u002F09-learning-loop\u002Fskill-creator\u002FSKILL.md",[],[]]