跳到正文
Skillpedia
API 与服务器(后端)7.6k · #13137

authentication

它能做什么

这项技能描述 Agent-Native 应用中的身份验证如何运作,它使用 Better Auth。内容涵盖开发模式和生产模式、受保护的自定义路由以及组织。适合设置或修复登录功能的开发者。

适用场景

  • ✓当你要为 Agent-Native 应用添加注册或登录功能的时候。
  • ✓当你希望保护某个自定义路由,只允许已登录用户使用的时候。
  • ✓当用户遇到会话问题,你需要找出原因的时候。

技能链接

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/authentication/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/authentication/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“你能为我的 Agent-Native 应用设置注册和登录,并提供 Google 登录作为选项吗?”

每周 5 个新技能,1 分钟读完。

工作原理

技能说明新用户在首次访问时如何获得账户,会话如何被检查,以及生产环境中有哪些登录方式可用。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Authentication

Rule

Auth is powered by Better Auth with account-first design. Every new user creates an account on first visit. Use getSession(event) to authenticate custom routes; actions are auto-protected. Normal app HTML and React Router page-data responses are one impersonal, public-cacheable shell for every visitor. The client decides whether to render private UI or redirect to sign-in.

Auth Modes

Mode Behavior
Development (default) Real Better Auth — same flow as production. There is no auth bypass. On first run the framework auto-creates a throwaway dev account and signs you in without printing its credentials (disable with AGENT_NATIVE_DISABLE_AUTO_DEV_ACCOUNT=1), so you are not stuck at a login wall. getSession() returns the signed-in user or null — it never falls back to a sentinel identity.
Production (default) Magic-link-first Better Auth when outbound email is ready, with email/password fallback and social providers (Google, GitHub). Organizations built in.
AUTH_MODE=local Not a browser auth bypass, and never returns local@localhost. It only affects CLI/agent identity: it lets pnpm action / the local agent loop auto-bind to the single real signed-in dev user from the sessions table (see scripts/dev-session.ts). Browser login is unchanged.
AUTH_SKIP_EMAIL_VERIFICATION=1 QA/preview escape hatch for password-fallback accounts. Signup skips email verification and does not send the signup verification email. Local dev/test skips verification by default; set AUTH_SKIP_EMAIL_VERIFICATION=0 only when testing verification itself. It does not change magic-link delivery. Give test accounts a test-identity address, such as an-e2e-probe-you@example.com or one containing +qa-test-bot- (the rule is isTestIdentityEmail in packages/core/src/shared/qa-test-email.ts), so they stay out of metrics. Test identities still get sign-in, verification, password-reset, and org-invitation mail, but no share notices or other app email.
auth.requireEmailVerification Declares the password-signup verification policy for any environment, production included, via defineAppConfig({ auth: { requireEmailVerification: false } }) or AUTH_REQUIRE_EMAIL_VERIFICATION=0. A declared value outranks AUTH_SKIP_EMAIL_VERIFICATION and the per-environment default. false accepts an unverified address as a login credential; true with no email provider disables password signup instead of stranding accounts on a verification nobody can deliver.
AUTH_MAGIC_LINK=0 Force the email/password fallback even when outbound email is ready.
AUTH_DISABLED=true Skip login/signup entirely — every request runs as dev@local.test. For local dev, cloud previews, and internal demos only; not for production with real users.
ACCESS_TOKEN / ACCESS_TOKENS Static bearer fallback for MCP/connect clients that cannot use OAuth. Not browser auth and never a token login page.
Custom Pass your own getSession to autoMountAuth(app, { getSession }).

Auth emails (verify signup, reset password, magic link, email change) and org invites render through renderTransactionalEmail. An app changes their copy or design with overrideTransactionalEmail(id, render) from a server plugin, never by editing better-auth-instance.ts call sites. See /docs/deployment#email-templates.

Hosted Sign-In Pages and the Shared Wave

  • First-party server auth plugins use createToolkitAuthPlugin from @agent-native/toolkit/app/auth/server. It server-renders AuthPage and ResetPasswordPage before hydration. Direct Core createAuthPlugin calls leave generic fallback markup in the response and can flash before React replaces it.
  • AuthPage uses Toolkit's full-page WaveBackground for every auth view. The Agent-Native homepage hero and Calendar booking use the same renderer: Calendar's animated FFT ocean wave. Keep the background empty while WebGPU support is checked and when the ocean renderer is unavailable
常见问题

开发时有办法跳过登录吗?

技能说明没有绕过身份验证的方法。首次运行时会自动创建一个开发账户。

自定义路由如何受到保护?

自定义路由使用会话检查,操作则会自动受到保护。

生产环境中有哪些登录选项?

技能提到了魔法链接、邮箱和密码备用方式,以及 Google 和 GitHub 社交登录。

详情

作者的原始描述

How auth works in agent-native apps. Use when wiring login/signup, configuring auth modes, setting up organizations, protecting routes, or debugging session issues.

repo: BuilderIO/agent-native

热度

GitHub 星标
7.6k
排名
#13137
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能