xiaohongshu
xiaohongshu
better-auth-best-practices
集成 Better Auth(TypeScript 鉴权框架)时使用。支持邮箱密码、OAuth、魔法链接、Passkey 等,通过插件扩展。编写或配置 Better Auth 时触发。
Full skill instructions
代码示例与最新 API 请查阅 better-auth.com/docs。
Better Auth 是 TypeScript 优先、框架无关的鉴权框架,通过插件支持邮箱/密码、OAuth、魔法链接、Passkey 等。
BETTER_AUTH_SECRET:加密密钥(至少 32 字符)。生成:openssl rand -base64 32BETTER_AUTH_URL:根 URL(如 https://example.com)仅当未设置环境变量时,在配置中定义 baseURL / secret。
CLI 在 ./、./lib、./utils 或 ./src 下查找 auth.ts。自定义路径用 --config。
npx @better-auth/cli@latest migrate — 应用 schema(内置 adapter)npx @better-auth/cli@latest generate — 为 Prisma/Drizzle 生成 schemanpx @better-auth/cli mcp --cursor — 为 AI 工具添加 MCP新增或修改插件后需重新执行。
| 选项 | 说明 |
|---|---|
appName | 可选显示名称 |
baseURL | 仅当未设置 BETTER_AUTH_URL 时 |
basePath | 默认 /api/auth,设为 / 可放在根路径 |
secret | 仅当未设置 BETTER_AUTH_SECRET 时 |
database | 多数功能必需,见 adapter 文档 |
secondaryStorage | Redis/KV,用于 session 与限流 |
emailAndPassword | { enabled: true } 启用 |
socialProviders | { google: { clientId, clientSecret }, ... } |
plugins | 插件数组 |
trustedOrigins | CSRF 白名单 |
直连:传入 pg.Pool、mysql2 池、better-sqlite3 或 bun:sqlite 实例。
ORM adapter:从 better-auth/adapters/drizzle、better-auth/adapters/prisma、better-auth/adapters/mongodb 等导入。
注意:Better Auth 使用 adapter 的 model 名,而非表名。若 Prisma model 为 User 对应表 users,用 modelName: "user"(Prisma 引用),而非 "users"。
存储优先级:
secondaryStorage → session 存此处(不存 DB)session.storeSessionInDatabase: true 可同时持久化到 DBcookieCache → 纯无状态模式Cookie 缓存策略:compact(默认)、jwt、jwe。
关键选项:session.expiresIn、session.updateAge、session.cookieCache.maxAge、session.cookieCache.version(变更可令所有 session 失效)。
User:user.modelName、user.fields、user.additionalFields、user.changeEmail.enabled、user.deleteUser.enabled。
Account:account.modelName、account.accountLinking.enabled、account.storeAccountCookie。
注册必需字段:email 与 name。
emailVerification.sendVerificationEmail — 验证邮件发送,必须定义emailVerification.sendOnSignUp / sendOnSignIn — 自动发送时机emailAndPassword.sendResetPassword — 重置密码邮件advanced 中:useSecureCookies、disableCSRFCheck(有风险)、disableOriginCheck(有风险)、crossSubDomainCookies.enabled、ipAddress.ipAddressHeaders、database.generateId 等。
限流:rateLimit.enabled、rateLimit.window、rateLimit.max、rateLimit.storage。
端点:hooks.before / hooks.after,{ matcher, handler } 数组,可用 createAuthMiddleware。
数据库:databaseHooks.user.create.before/after 等,用于默认值或创建后逻辑。
Hook 上下文:session、secret、adapter、generateId()、baseURL 等。
按路径导入以支持 tree-shaking:
import { twoFactor } from "better-auth/plugins/two-factor"
勿从 "better-auth/plugins" 整体导入。
常用插件:twoFactor、organization、passkey、magicLink、emailOtp、username、admin、apiKey、bearer、jwt、multiSession、sso、openAPI 等。
客户端插件放在 createAuthClient({ plugins: [...] })。
从 better-auth/client、better-auth/react、better-auth/vue 等导入。
常用方法:signUp.email()、signIn.email()、signIn.social()、signOut()、useSession()、getSession()、revokeSession() 等。
推断类型:typeof auth.$Infer.Session、typeof auth.$Infer.Session.user。
前后端分离项目:createAuthClient()。
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience