authentication
Skill này làm gì
Skill này mô tả cách xác thực hoạt động trong ứng dụng Agent-Native, dùng Better Auth. Nó bao gồm chế độ phát triển và chế độ production, việc bảo vệ các route tùy chỉnh và tổ chức. Skill dành cho lập trình viên thiết lập hoặc sửa chức năng đăng nhập.
Khi nào nên dùng
- ✓Khi bạn thêm đăng ký hoặc đăng nhập vào ứng dụng Agent-Native.
- ✓Khi bạn muốn bảo vệ một route tùy chỉnh để chỉ người đã đăng nhập mới dùng được.
- ✓Khi người dùng gặp lỗi phiên và bạn cần tìm nguyên nhân.
Liên kết skill
https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/authentication/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể thiết lập đăng ký và đăng nhập cho ứng dụng Agent-Native của tôi, với đăng nhập Google là một lựa chọn không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill giải thích cách người dùng mới có tài khoản ở lần truy cập đầu tiên, cách phiên được kiểm tra, và những phương thức đăng nhập nào có sẵn trong production.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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
createToolkitAuthPluginfrom@agent-native/toolkit/app/auth/server. It server-rendersAuthPageandResetPasswordPagebefore hydration. Direct CorecreateAuthPlugincalls leave generic fallback markup in the response and can flash before React replaces it. AuthPageuses Toolkit's full-pageWaveBackgroundfor 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
Câu hỏi thường gặp
Có cách nào bỏ qua đăng nhập khi phát triển không?
Skill nói không có cơ chế bỏ qua xác thực. Lần chạy đầu tiên, một tài khoản phát triển được tạo tự động.
Các route tùy chỉnh được bảo vệ thế nào?
Route tùy chỉnh dùng kiểm tra phiên, còn action được bảo vệ tự động.
Có những tùy chọn đăng nhập nào trong production?
Skill nhắc đến magic link, email và mật khẩu dự phòng, cùng đăng nhập xã hội qua Google và GitHub.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 7.6k
- Vị trí xếp hạng
- #13137
- Giấy phép
- MIT
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
design-exploration
7.6kGiúp agent của bạn khám phá nhiều hướng thiết kế giao diện song song, để bạn chọn một hướng rồi tinh chỉnh thiết kế đã chọn.
visual-edit
7.6kGiúp agent của bạn mở một ứng dụng cục bộ đang chạy trong trình chỉnh sửa trực quan, để bạn xem và sửa các màn hình thật cùng nhau.
turn-into-app
7.6kBiến quy trình, bảng tính hoặc dự án thành ứng dụng trực quan có màn hình đầy đủ dữ liệu, với agent làm việc phía sau các điều khiển.
visual-plan
7.6kBiến một kế hoạch viết bằng văn bản thuần thành kế hoạch trực quan tương tác, có sơ đồ, bản đồ file, đoạn code và các câu hỏi còn mở.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.