better-auth-authentication
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBetter Auth Authentication
Better Auth 认证
Goals
目标
- Enable email/password authentication and social providers.
- Implement sign-up, sign-in, sign-out, and verification flows.
- Handle redirects and errors consistently.
- 启用邮箱/密码认证和社交登录提供商。
- 实现注册、登录、登出和验证流程。
- 统一处理重定向和错误。
Quick start
快速开始
- Enable and configure
emailAndPassword.socialProviders - Create a client with .
createAuthClient - Use ,
signUp.email,signIn.email, andsignIn.socialon the client.signOut
ts
import { betterAuth } from "better-auth";
export const auth = betterAuth({
emailAndPassword: { enabled: true },
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
},
});ts
import { createAuthClient } from "better-auth/client";
const authClient = createAuthClient();
await authClient.signUp.email({
email,
password,
name,
});
await authClient.signIn.email({
email,
password,
callbackURL: "/dashboard",
});
await authClient.signIn.social({
provider: "github",
callbackURL: "/dashboard",
});
await authClient.signOut();- 启用并配置
emailAndPassword。socialProviders - 使用创建客户端。
createAuthClient - 在客户端上调用、
signUp.email、signIn.email和signIn.social方法。signOut
ts
import { betterAuth } from "better-auth";
export const auth = betterAuth({
emailAndPassword: { enabled: true },
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
},
});ts
import { createAuthClient } from "better-auth/client";
const authClient = createAuthClient();
await authClient.signUp.email({
email,
password,
name,
});
await authClient.signIn.email({
email,
password,
callbackURL: "/dashboard",
});
await authClient.signIn.social({
provider: "github",
callbackURL: "/dashboard",
});
await authClient.signOut();Email verification
邮箱验证
- Provide to send the verification link.
emailVerification.sendVerificationEmail - Use to enforce verification before sign-in.
emailAndPassword.requireEmailVerification
- 调用发送验证链接。
emailVerification.sendVerificationEmail - 使用强制用户在登录前完成验证。
emailAndPassword.requireEmailVerification
Social providers
社交登录提供商
- Configure providers in with provider-specific credentials.
socialProviders - Use to start OAuth flows.
signIn.social - Pass ,
callbackURL, anderrorCallbackURLfor redirects.newUserCallbackURL
- 在中配置各提供商的专属凭证。
socialProviders - 使用启动OAuth流程。
signIn.social - 传入、
callbackURL和errorCallbackURL以处理重定向。newUserCallbackURL
Guardrails
注意事项
- Call client methods from the client only.
- Keep secrets in server-only env variables.
- Use to control persistent sessions on email/password sign-in.
rememberMe
- 仅在客户端调用客户端方法。
- 密钥需存储在仅服务器可访问的环境变量中。
- 在邮箱/密码登录时使用控制会话的持久性。
rememberMe
References
参考文档
toolchains/platforms/auth/better-auth/better-auth-authentication/references/email-password.mdtoolchains/platforms/auth/better-auth/better-auth-authentication/references/providers.md
toolchains/platforms/auth/better-auth/better-auth-authentication/references/email-password.mdtoolchains/platforms/auth/better-auth/better-auth-authentication/references/providers.md