Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计提醒

better-authBetter Auth 认证

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

470

周安装

20

GitHub Stars

3

下载量

165
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:better-auth(Better Auth 认证)
来源仓库:https://github.com/fellipeutaka/leon
仓库路径:skills/better-auth
安装命令:
npx skills add https://github.com/fellipeutaka/leon --skill better-auth
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/fellipeutaka/leon --skill better-auth

简介

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。

  • 使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。
  • 当前顶部介绍为空,原始 SKILL.md 摘录未提供。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • better-auth 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Better Auth

Framework-agnostic TypeScript auth library. Plugin-based architecture, 40+ OAuth providers, 18+ framework integrations.

Quick Start

Install

npm install better-auth

Scoped packages (as needed):

PackageUse case
@better-auth/passkeyWebAuthn/Passkey auth
@better-auth/ssoSAML/OIDC enterprise SSO
@better-auth/stripeStripe payments
@better-auth/expoReact Native/Expo

Environment Variables

BETTER_AUTH_SECRET=<32+ chars, generate: openssl rand -base64 32>
BETTER_AUTH_URL=http://localhost:3000
DATABASE_URL=<connection string>

Server Config (lib/auth.ts)

import { betterAuth } from "better-auth";

export const auth = betterAuth({
  database: process.env.DATABASE_URL,  // or adapter instance
  emailAndPassword: { enabled: true },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    },
  },
  plugins: [], // add plugins here
});

export type Session = typeof auth.$Infer.Session;

Client Config (lib/auth-client.ts)

import { createAuthClient } from "better-auth/react"; // or /vue, /svelte, /solid, /client

export const authClient = createAuthClient({
  plugins: [], // add client plugins here
});

Route Handler

FrameworkFileHandler
Next.js App Routerapp/api/auth/[...all]/route.tstoNextJsHandler(auth) → export {GET, POST}
Next.js Pagespages/api/auth/[...all].tstoNextJsHandler(auth) → default export
Expressanyapp.all("/api/auth/*splat", toNodeHandler(auth))
Honorouteapp.on(["POST","GET"], "/api/auth/**", (c) => auth.handler(c.req.raw))
SvelteKithooks.server.tssvelteKitHandler({auth, event})
Astropages/api/auth/[...all].tstoAstroHandler(auth)
Elysiapluginnew Elysia().mount(auth.handler)

See references/framework-integrations.md for all frameworks.

CLI Commands

npx @better-auth/cli@latest migrate          # Apply schema (built-in adapter)
npx @better-auth/cli@latest generate          # Generate for Prisma/Drizzle
npx @better-auth/cli@latest generate --output prisma/schema.prisma
npx @better-auth/cli@latest generate --output src/db/auth-schema.ts

Re-run after adding/changing plugins.

Core Concepts

  • Server instance (auth): handles all auth logic, DB, sessions
  • Client instance (authClient): framework-specific hooks (useSession, signIn, signUp, signOut)
  • Plugins: extend both server and client — add endpoints, DB tables, hooks
  • Type inference: auth.$Infer.Session, auth.$Infer.Session.user for full type safety
  • For separate client/server projects: createAuthClient<typeof auth>()

Authentication Methods

MethodPackageConfig/PluginReference
Email/Passwordbuilt-inemailAndPassword: {enabled: true}authentication.md
Social OAuthbuilt-insocialProviders: {google: {...}}authentication.md
Magic Linkbuilt-inmagicLink() pluginauthentication.md
Passkey@better-auth/passkeypasskey() pluginauthentication.md
Usernamebuilt-inusername() pluginauthentication.md
Email OTPbuilt-inemailOtp() pluginauthentication.md
Phone Numberbuilt-inphoneNumber() pluginauthentication.md
Anonymousbuilt-inanonymous() pluginauthentication.md

Plugin Quick Reference

Import from dedicated paths for tree-shaking: import {twoFactor} from "better-auth/plugins/two-factor" NOT from "better-auth/plugins".

PluginServer ImportClient ImportPurpose
twoFactorbetter-auth/plugins/two-factortwoFactorClientTOTP, OTP, backup codes
organizationbetter-auth/plugins/organizationorganizationClientMulti-tenant orgs, teams, RBAC
adminbetter-auth/plugins/adminadminClientUser management, impersonation
passkey@better-auth/passkeypasskeyClientWebAuthn/FIDO2
magicLinkbetter-auth/plugins/magic-linkmagicLinkClientPasswordless email links
emailOtpbetter-auth/plugins/email-otpemailOtpClientEmail one-time passwords
usernamebetter-auth/plugins/usernameusernameClientUsername-based auth
phoneNumberbetter-auth/plugins/phone-numberphoneNumberClientPhone-based auth
anonymousbetter-auth/plugins/anonymousanonymousClientGuest sessions
apiKeybetter-auth/plugins/api-keyapiKeyClientAPI key management
bearerbetter-auth/plugins/bearerBearer token auth
jwtbetter-auth/plugins/jwtjwtClientJWT tokens
multiSessionbetter-auth/plugins/multi-sessionmultiSessionClientMultiple active sessions
oauthProviderbetter-auth/plugins/oauth-providerBecome OAuth provider
oidcProviderbetter-auth/plugins/oidc-providerBecome OIDC provider
sso@better-auth/ssossoClientSAML/OIDC enterprise SSO
openAPIbetter-auth/plugins/open-apiAPI documentation
customSessionbetter-auth/plugins/custom-sessionExtend session data
genericOAuthbetter-auth/plugins/generic-oauthgenericOAuthClientCustom OAuth providers
oneTapbetter-auth/plugins/one-taponeTapClientGoogle One Tap

Pattern: server plugin in auth({plugins: [...]}) + client plugin in createAuthClient({plugins: [...]}) + re-run CLI migrations.

See references/plugins.md for detailed usage and custom plugin creation.

Database Setup

AdapterSetup
SQLitePass better-sqlite3 or bun:sqlite instance
PostgreSQLPass pg.Pool instance
MySQLPass mysql2 pool
PrismaprismaAdapter(prisma, {provider: "postgresql"}) from better-auth/adapters/prisma
DrizzledrizzleAdapter(db, {provider: "pg"}) from better-auth/adapters/drizzle
MongoDBmongodbAdapter(db) from better-auth/adapters/mongodb
Connection stringdatabase: process.env.DATABASE_URL (uses built-in Kysely)

Critical: Config uses ORM model name, NOT DB table name. Prisma model User mapping to table users → use modelName: "user".

Core schema tables: user, session, account, verification. Plugins add their own tables.

See references/setup.md for full database setup details.

Session Management

Key options:

session: {
  expiresIn: 60 * 60 * 24 * 7,  // 7 days (default)
  updateAge: 60 * 60 * 24,       // refresh every 24h (default)
  freshAge: 60 * 60 * 24,        // require re-auth after 24h for sensitive ops
  cookieCache: {
    enabled: true,
    maxAge: 300,                  // 5 min
    strategy: "compact",          // "compact" | "jwt" | "jwe"
  },
}
  • secondaryStorage (Redis/KV): sessions go there by default, not DB
  • Stateless mode: no DB + cookieCache = session in cookie only
  • customSession plugin: extend session with custom fields

See references/sessions.md for full session management details.

Security Checklist

DODON'T
Use 32+ char secret with high entropyCommit secrets to version control
Set baseURL with HTTPS in productionDisable CSRF check (disableCSRFCheck)
Configure trustedOrigins for all frontendsDisable origin check
Enable rate limiting (on by default in prod)Use "memory" rate limit storage in serverless
Configure backgroundTasks.handler on serverlessSkip email verification setup
Use "jwe" cookie cache for sensitive session dataStore OAuth tokens unencrypted if used for API calls
Set revokeSessionsOnPasswordReset: trueReturn specific error messages ("user not found")

See references/security.md for complete security hardening guide.

Common Gotchas

  1. Model vs table name — config uses ORM model name, not DB table name
  2. Plugin schema — re-run CLI after adding/changing plugins
  3. Secondary storage — sessions go there by default, not DB. Set session.storeSessionInDatabase: true to persist both
  4. Cookie cache — custom session fields NOT cached, always re-fetched from DB
  5. Callback URLs — always use absolute URLs with origin (not relative paths)
  6. Express v5 — use "/api/auth/*splat" not "/api/auth/*" for catch-all routes
  7. Next.js RSC — add nextCookies() plugin to auth config for server component session access

Troubleshooting

IssueFix
"Secret not set"Add BETTER_AUTH_SECRET env var
"Invalid Origin"Add domain to trustedOrigins
Cookies not settingCheck baseURL matches domain; enable secure cookies in prod
OAuth callback errorsVerify redirect URIs in provider dashboard match exactly
Type errors after adding pluginRe-run CLI generate/migrate
Session null in RSCAdd nextCookies() plugin
2FA redirect not workingAdd twoFactorClient with onTwoFactorRedirect to client

Reference Index

FileWhen to read
setup.mdSetting up new project, configuring DB, route handlers
authentication.mdImplementing any auth method (email, social, passkey, magic link, etc.)
sessions.mdConfiguring session expiry, caching, stateless mode, secondary storage
security.mdHardening for production — rate limiting, CSRF, cookies, OAuth security
plugins.mdUsing or creating plugins, plugin catalog
framework-integrations.mdFramework-specific setup (Next.js, Nuxt, SvelteKit, Hono, Express, etc.)
two-factor.mdImplementing 2FA (TOTP, OTP, backup codes, trusted devices)
organizations.mdMulti-tenant orgs, teams, invitations, RBAC
admin.mdUser management, roles, banning, impersonation
hooks-and-middleware.mdCustom logic via before/after hooks, DB hooks, middleware

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.82%
按下载量换算56

Claude

28.49%
按下载量换算47

Cursor

19.22%
按下载量换算32

Gemini CLI

8.77%
按下载量换算14

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills