[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M75BDZN8YHKEZDD1NFSCGYCG":3,"skill-same:01M75BDZN8YHKEZDD1NFSCGYCG":44},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":14,"categories":15,"keywords":16,"publishedAt":17,"linkOnly":18,"markdownContent":19,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":25,"repositoryHtmlUrl":26,"repositoryHomepageUrl":27,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M75BDZN8YHKEZDD1NFSCGYCG","better-auth-best-practices",null,"ruake\u002FAWARE","ruake","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F253885939?v=4","01M75AVBM7FRFTS61RZRNMZB6C","01M75AVBMYHD7500NHVANF1HKM",0,"MIT","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fbetter-auth-best-practices\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: better-auth-best-practices\ndescription: **Always consult [better-auth.com\u002Fdocs](https:\u002F\u002Fbetter-auth.com\u002Fdocs) for code examples and latest API.**\n---\n\n# 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\n---\n\n## Setup Workflow\n\n1. Install: `npm install better-auth`\n2. Set env vars: `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL`\n3. Create `auth.ts` with database + config\n4. Create route handler for your framework\n5. Run `npx @better-auth\u002Fcli@latest migrate`\n6. Verify: call `GET \u002Fapi\u002Fauth\u002Fok` — should return `{ status: \"ok\" }`\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","# 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\n---\n\n## Setup Workflow\n\n1. Install: `npm install better-auth`\n2. Set env vars: `BETTER_AUTH_SECRET` and `BETTER_AUTH_URL`\n3. Create `auth.ts` with database + config\n4. Create route handler for your framework\n5. Run `npx @better-auth\u002Fcli@latest migrate`\n6. Verify: call `GET \u002Fapi\u002Fauth\u002Fok` — should return `{ status: \"ok\" }`\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","6184979e01f673905139589c194eab38198db2f7",".opencode\u002Fskills\u002Fbetter-auth-best-practices",1,"https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE","https:\u002F\u002Fruake.github.io\u002FAWARE","https:\u002F\u002Fgithub.com\u002Fruake","2026-11-15 04:27:27",{"source":7,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add ruake\u002FAWARE --skill better-auth-best-practices",{"tool":36,"command":37},"bunx","bunx skills add ruake\u002FAWARE --skill better-auth-best-practices",{"tool":39,"command":40},"pnpm","pnpm dlx skills add ruake\u002FAWARE --skill better-auth-best-practices","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fbetter-auth-best-practices\u002FSKILL.md",true,[],[45,51,58,65,72,78],{"skillNo":46,"name":47,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":48,"categories":49,"keywords":50,"publishedAt":17},"01M75BPBYT89TEE87CGBDX2KF5","xlsx","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fxlsx\u002FSKILL.md",[],[],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":17},"01M75BPA000S9MTH5MY7CZNYYQ","writing-plans","Write comprehensive implementation plans assuming the engineer has zero context for our codebase and questionable taste.","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fwriting-plans\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":17},"01M75BP80ETH9GYVRH8A7QPCSG","web-design-guidelines","Review files for compliance with Web Interface Guidelines.","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fweb-design-guidelines\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":17},"01M75BP5XG8SX5Q2WWZB6QRVFT","web-component-design","Build reusable, maintainable UI components using modern frameworks with clean composition patterns and styling approache","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fweb-component-design\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":17},"01M75BP4B1FC4V81QR1VB56H1E","web-artifacts-builder","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fweb-artifacts-builder\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":6,"repositoryNo":11,"starsCount":12,"licenseSpdxId":13,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":17},"01M75BP1XVRW8WQ2XXAJBAYV2V","vueuse-functions","This skill is a decision-and-implementation guide for VueUse composables in Vue.js \u002F Nuxt projects. It maps requirements","https:\u002F\u002Fgithub.com\u002Fruake\u002FAWARE\u002Fblob\u002Fmain\u002F.opencode\u002Fskills\u002Fvueuse-functions\u002FSKILL.md",[],[]]