[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6ECSD7D3H44J8E60J1VPW57":3,"skill-same:01M6ECSD7D3H44J8E60J1VPW57":55},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":22,"linkOnly":23,"markdownContent":24,"markdownBody":24,"frontMatter":25,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":31,"ownerHtmlUrl":32,"ownerBlogUrl":6,"ownerDescription":33,"updatedAt":34,"install":35,"resources":48},"01M6ECSD7D3H44J8E60J1VPW57","better-auth-best-practices",null,"ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FLeoYeAI\u002Fopenclaw-master-skills\u002Fbetter-auth-best-practices\u002FSKILL.md",[],[18,19,20,21],"auth","best practices","better auth best practices","better auth","2026-11-10 10:12:30",false,"# Better Auth Integration Guide\n\n**Always consult [better-auth.com\u002Fdocs](https:\u002F\u002Fbetter-auth.com\u002Fdocs) for code examples and latest API.**\n\nBetter Auth is a TypeScript-first, framework-agnostic auth framework supporting email\u002Fpassword, OAuth, magic links, passkeys, and more via plugins.\n\n---\n\n## Quick Reference\n\n### Environment Variables\n- `BETTER_AUTH_SECRET` - Encryption secret (min 32 chars). Generate: `openssl rand -base64 32`\n- `BETTER_AUTH_URL` - Base URL (e.g., `https:\u002F\u002Fexample.com`)\n\nOnly define `baseURL`\u002F`secret` in config if env vars are NOT set.\n\n### File Location\nCLI looks for `auth.ts` in: `.\u002F`, `.\u002Flib`, `.\u002Futils`, or under `.\u002Fsrc`. Use `--config` for custom path.\n\n### CLI Commands\n- `npx @better-auth\u002Fcli@latest migrate` - Apply schema (built-in adapter)\n- `npx @better-auth\u002Fcli@latest generate` - Generate schema for Prisma\u002FDrizzle\n- `npx @better-auth\u002Fcli mcp --cursor` - Add MCP to AI tools\n\n**Re-run after adding\u002Fchanging plugins.**\n\n---\n\n## Core Config Options\n\n| Option | Notes |\n|--------|-------|\n| `appName` | Optional display name |\n| `baseURL` | Only if `BETTER_AUTH_URL` not set |\n| `basePath` | Default `\u002Fapi\u002Fauth`. Set `\u002F` for root. |\n| `secret` | Only if `BETTER_AUTH_SECRET` not set |\n| `database` | Required for most features. See adapters docs. |\n| `secondaryStorage` | Redis\u002FKV for sessions & rate limits |\n| `emailAndPassword` | `{ enabled: true }` to activate |\n| `socialProviders` | `{ google: { clientId, clientSecret }, ... }` |\n| `plugins` | Array of plugins |\n| `trustedOrigins` | CSRF whitelist |\n\n---\n\n## Database\n\n**Direct connections:** Pass `pg.Pool`, `mysql2` pool, `better-sqlite3`, or `bun:sqlite` instance.\n\n**ORM adapters:** Import from `better-auth\u002Fadapters\u002Fdrizzle`, `better-auth\u002Fadapters\u002Fprisma`, `better-auth\u002Fadapters\u002Fmongodb`.\n\n**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\"`.\n\n---\n\n## Session Management\n\n**Storage priority:**\n1. If `secondaryStorage` defined → sessions go there (not DB)\n2. Set `session.storeSessionInDatabase: true` to also persist to DB\n3. No database + `cookieCache` → fully stateless mode\n\n**Cookie cache strategies:**\n- `compact` (default) - Base64url + HMAC. Smallest.\n- `jwt` - Standard JWT. Readable but signed.\n- `jwe` - Encrypted. Maximum security.\n\n**Key options:** `session.expiresIn` (default 7 days), `session.updateAge` (refresh interval), `session.cookieCache.maxAge`, `session.cookieCache.version` (change to invalidate all sessions).\n\n---\n\n## User & Account Config\n\n**User:** `user.modelName`, `user.fields` (column mapping), `user.additionalFields`, `user.changeEmail.enabled` (disabled by default), `user.deleteUser.enabled` (disabled by default).\n\n**Account:** `account.modelName`, `account.accountLinking.enabled`, `account.storeAccountCookie` (for stateless OAuth).\n\n**Required for registration:** `email` and `name` fields.\n\n---\n\n## Email Flows\n\n- `emailVerification.sendVerificationEmail` - Must be defined for verification to work\n- `emailVerification.sendOnSignUp` \u002F `sendOnSignIn` - Auto-send triggers\n- `emailAndPassword.sendResetPassword` - Password reset email handler\n\n---\n\n## Security\n\n**In `advanced`:**\n- `useSecureCookies` - Force HTTPS cookies\n- `disableCSRFCheck` - ⚠️ Security risk\n- `disableOriginCheck` - ⚠️ Security risk  \n- `crossSubDomainCookies.enabled` - Share cookies across subdomains\n- `ipAddress.ipAddressHeaders` - Custom IP headers for proxies\n- `database.generateId` - Custom ID generation or `\"serial\"`\u002F`\"uuid\"`\u002F`false`\n\n**Rate limiting:** `rateLimit.enabled`, `rateLimit.window`, `rateLimit.max`, `rateLimit.storage` (\"memory\" | \"database\" | \"secondary-storage\").\n\n---\n\n## Hooks\n\n**Endpoint hooks:** `hooks.before` \u002F `hooks.after` - Array of `{ matcher, handler }`. Use `createAuthMiddleware`. Access `ctx.path`, `ctx.context.returned` (after), `ctx.context.session`.\n\n**Database hooks:** `databaseHooks.user.create.before\u002Fafter`, same for `session`, `account`. Useful for adding default values or post-creation actions.\n\n**Hook context (`ctx.context`):** `session`, `secret`, `authCookies`, `password.hash()`\u002F`verify()`, `adapter`, `internalAdapter`, `generateId()`, `tables`, `baseURL`.\n\n---\n\n## Plugins\n\n**Import from dedicated paths for tree-shaking:**\n```\nimport { twoFactor } from \"better-auth\u002Fplugins\u002Ftwo-factor\"\n```\nNOT `from \"better-auth\u002Fplugins\"`.\n\n**Popular plugins:** `twoFactor`, `organization`, `passkey`, `magicLink`, `emailOtp`, `username`, `phoneNumber`, `admin`, `apiKey`, `bearer`, `jwt`, `multiSession`, `sso`, `oauthProvider`, `oidcProvider`, `openAPI`, `genericOAuth`.\n\nClient plugins go in `createAuthClient({ plugins: [...] })`.\n\n---\n\n## Client\n\nImport from: `better-auth\u002Fclient` (vanilla), `better-auth\u002Freact`, `better-auth\u002Fvue`, `better-auth\u002Fsvelte`, `better-auth\u002Fsolid`.\n\nKey methods: `signUp.email()`, `signIn.email()`, `signIn.social()`, `signOut()`, `useSession()`, `getSession()`, `revokeSession()`, `revokeSessions()`.\n\n---\n\n## Type Safety\n\nInfer types: `typeof auth.$Infer.Session`, `typeof auth.$Infer.Session.user`.\n\nFor separate client\u002Fserver projects: `createAuthClient\u003Ctypeof auth>()`.\n\n---\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 plugins\n3. **Secondary storage** - Sessions go there by default, not DB\n4. **Cookie cache** - Custom session fields NOT cached, always re-fetched\n5. **Stateless mode** - No DB = session in cookie only, logout on cache expiry\n6. **Change email flow** - Sends to current email first, then new email\n\n---\n\n## Resources\n\n- [Docs](https:\u002F\u002Fbetter-auth.com\u002Fdocs)\n- [Options Reference](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Freference\u002Foptions)\n- [LLMs.txt](https:\u002F\u002Fbetter-auth.com\u002Fllms.txt)\n- [GitHub](https:\u002F\u002Fgithub.com\u002Fbetter-auth\u002Fbetter-auth)\n- [Init Options Source](https:\u002F\u002Fgithub.com\u002Fbetter-auth\u002Fbetter-auth\u002Fblob\u002Fmain\u002Fpackages\u002Fcore\u002Fsrc\u002Ftypes\u002Finit-options.ts)\n",{},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002FLeoYeAI\u002Fopenclaw-master-skills\u002Fbetter-auth-best-practices",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":7,"skillName":5,"commands":36,"prompt":46,"zipAvailable":47},[37,40,43],{"tool":38,"command":39},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill better-auth-best-practices",{"tool":41,"command":42},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill better-auth-best-practices",{"tool":44,"command":45},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill better-auth-best-practices","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FLeoYeAI\u002Fopenclaw-master-skills\u002Fbetter-auth-best-practices\u002FSKILL.md",true,[49],{"path":50,"resourceType":51,"resourceTypeDesc":52,"sizeBytes":53,"sourceHtmlUrl":54},"LICENSE.txt","LICENSE","许可证",11345,"https:\u002F\u002Fgithub.com\u002Fa1627418541\u002F-\u002Fblob\u002Fmain\u002F.trae\u002Fskills\u002Fbrand-guidelines\u002FLICENSE.txt",[56,65,74,83,89,95],{"skillNo":57,"name":58,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":22},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[62,63,64],"model","model hierarchy","model hierarchy skill",{"skillNo":66,"name":67,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":22},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[71,72,73],"MCP","zoom","zoom mcp",{"skillNo":75,"name":76,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":22},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[80,81,82,72],"sdk","zoom apps sdk","apps",{"skillNo":84,"name":85,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":22},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[85],{"skillNo":90,"name":91,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":22},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[91],{"skillNo":96,"name":97,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":22},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[97]]