About better-auth-authentication
A development guide to configuring Better Auth and using its client methods for applications that need email/password and social sign-in flows. It also covers email verification, redirects, error handling, and secret management.
Key features
- 01Email/password sign-up and sign-in
- 02Social provider OAuth sign-in
- 03Email verification flows
- 04Callback and error redirects
- 05Persistent session control
Use cases
- 01Add email/password authentication to an app
- 02Configure GitHub or other social sign-in
- 03Require email verification before sign-in
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ bobmatnyc/ claude-mpm-skills --skill better-auth-authenticationAfter installing, type/better-auth-authenticationin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
metadata.jsonreferences/email-password.mdproviders.mdDetails
From the project READMEBetter Auth Authentication
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
emailAndPasswordand configuresocialProviders. - Create a client with
createAuthClient. - Use
signUp.email,signIn.email,signIn.social, andsignOuton the client.
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,
},
},
});
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
emailVerification.sendVerificationEmailto send the verification link. - Use
emailAndPassword.requireEmailVerificationto enforce verification before sign-in.
Social providers
- Configure providers in
socialProviderswith provider-specific credentials. - Use
signIn.socialto start OAuth flows. - Pass
callbackURL,errorCallbackURL, andnewUserCallbackURLfor redirects.
Guardrails
- Call client methods from the client only.
- Keep secrets in server-only env variables.
- Use
rememberMeto control persistent sessions on email/password sign-in.
References
toolchains/platforms/auth/better-auth/better-auth-authentication/references/email-password.mdtoolchains/platforms/auth/better-auth/better-auth-authentication/references/providers.md
Comments
Markdown supported