본문으로 건너뛰기
cccskills
무료GitHub에 공개

email-and-password-best-practices

Configure email verification, implement password reset flows, set password policies, and customise hashing algorithms for Better Auth email/password authentication. Use when users need to set up login, sign-in, sign-up, credential authentication, or password security with Better Auth.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works스타 182(GitHub 182 + cccskills 0)

실행 점수 미검증

설치 방법 보기

포함된 파일(1)

  • SKILL.md5.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Quick Start

  1. Enable email/password: emailAndPassword: { enabled: true }
  2. Configure emailVerification.sendVerificationEmail
  3. Add sendResetPassword for password reset flows
  4. Run npx @better-auth/cli@latest migrate
  5. Verify: attempt sign-up and confirm verification email triggers

Email Verification Setup

Configure emailVerification.sendVerificationEmail to verify user email addresses.

import { betterAuth } from 'better-auth';
import { sendEmail } from './email'; // your email sending function

export const auth = betterAuth({
	emailVerification: {
		sendVerificationEmail: async ({ user, url, token }, request) => {
			await sendEmail({
				to: user.email,
				subject: 'Verify your email address',
				text: `Click the link to verify your email: ${url}`
			});
		}
	}
});

Note: The url parameter contains the full verification link. The token is available if you need to build a custom verification URL.

Requiring Email Verification

For stricter security, enable emailAndPassword.requireEmailVerification to block sign-in until the user verifies their email. When enabled, unverified users will receive a new verification email on each sign-in attempt.

export const auth = betterAuth({
	emailAndPassword: {
		requireEmailVerification: true
	}
});

Note: This requires sendVerificationEmail to be configured and only applies to email/password sign-ins.

Client Side Validation

Implement client-side validation for immediate user feedback and reduced server load.

Callback URLs

Always use absolute URLs (including the origin) for callback URLs in sign-up and sign-in requests. This prevents Better Auth from needing to infer the origin, which can cause issues when your backend and frontend are on different domains.

const { data, error } = await authClient.signUp.email({
	callbackURL: 'https://example.com/callback' // absolute URL with origin
});

Password Reset Flows

Provide sendResetPassword in the email and password config to enable password resets.

import { betterAuth } from 'better-auth';
import { sendEmail } from './email'; // your email sending function

export const auth = betterAuth({
	emailAndPassword: {
		enabled: true,
		// Custom email sending function to send reset-password email
		sendResetPassword: async ({ user, url, token }, request) => {
			void sendEmail({
				to: user.email,
				subject: 'Reset your password',
				text: `Click the link to reset your password: ${url}`
			});
		},
		// Optional event hook
		onPasswordReset: async ({ user }, request) => {
			// your logic here
			console.log(`Password for user ${user.email} has been reset.`);
		}
	}
});

Security Considerations

Built-in protections: background email sending (timing attack prevention), dummy operations on invalid requests, constant response messages regardless of user existence.

On serverless platforms, configure a background task handler:

export const auth = betterAuth({
	advanced: {
		backgroundTasks: {
			handler: (promise) => {
				// Use platform-specific methods like waitUntil
				waitUntil(promise);
			}
		}
	}
});

Token Security

Tokens expire after 1 hour by default. Configure with resetPasswordTokenExpiresIn (in seconds):

export const auth = betterAuth({
	emailAndPassword: {
		enabled: true,
		resetPasswordTokenExpiresIn: 60 * 30 // 30 minutes
	}
});

Tokens are single-use — deleted immediately after successful reset.

Session Revocation

Enable revokeSessionsOnPasswordReset to invalidate all existing sessions on password reset:

export const auth = betterAuth({
	emailAndPassword: {
		enabled: true,
		revokeSessionsOnPasswordReset: true
	}
});

Password Requirements

Password length limits (configurable):

export const auth = betterAuth({
	emailAndPassword: {
		enabled: true,
		minPasswordLength: 12,
		maxPasswordLength: 256
	}
});

Sending the Password Reset

Call requestPasswordReset to send the reset link. Triggers the sendResetPassword function from your config.

const data = await auth.api.requestPasswordReset({
	body: {
		email: 'john.doe@example.com', // required
		redirectTo: 'https://example.com/reset-password'
	}
});

Or authClient:

const { data, error } = await authClient.requestPasswordReset({
	email: 'john.doe@example.com', // required
	redirectTo: 'https://example.com/reset-password'
});

Note: While the email is required, we also recommend configuring the redirectTo for a smoother user experience.

Password Hashing

Default: scrypt (Node.js native, no external dependencies).

Custom Hashing Algorithm

To use Argon2id or another algorithm, provide custom hash and verify functions:

import { betterAuth } from 'better-auth';
import { hash, verify, type Options } from '@node-rs/argon2';

const argon2Options: Options = {
	memoryCost: 65536, // 64 MiB
	timeCost: 3, // 3 iterations
	parallelism: 4, // 4 parallel lanes
	outputLen: 32, // 32 byte output
	algorithm: 2 // Argon2id variant
};

export const auth = betterAuth({
	emailAndPassword: {
		enabled: true,
		password: {
			hash: (password) => hash(password, argon2Options),
			verify: ({ password, hash: storedHash }) => verify(storedHash, password, argon2Options)
		}
	}
});

Note: If you switch hashing algorithms on an existing system, users with passwords hashed using the old algorithm won't be able to sign in. Plan a migration strategy if needed.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Audit and improve web accessibility following WCAG 2.2 guidelines. Use when asked to "improve accessibility", "a11y audit", "WCAG compliance", "screen reader support", "keyboard navigation", or "make accessible".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works1822026년 10월 24일 업데이트

ai-sdk

무료

Answer questions about the AI SDK and help build AI-powered features. Use when developers: (1) Ask about AI SDK functions like generateText, streamText, ToolLoopAgent, embed, or tools, (2) Want to build AI agents, chatbots, RAG systems, or text generation features, (3) Have questions about AI providers (OpenAI, Anthropic, Google, etc.), streaming, tool calling, structured output, or embeddings, (4) Use React hooks like useChat or useCompletion. Triggers on: "AI SDK", "Vercel AI SDK", "generateText", "streamText", "add AI to my app", "build an agent", "tool calling", "structured output", "useChat".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works1822026년 10월 24일 업데이트

Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention Better Auth, betterauth, auth.ts, or need to set up TypeScript authentication with email/password, OAuth, or plugin configuration.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works1822026년 10월 24일 업데이트

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works1822026년 10월 24일 업데이트

Repo-specific guide to the Ever Works monorepo (ever-works/ever-works) — its pnpm + Turborepo layout, the per-workspace test runners (Jest vs Vitest vs Playwright), file-naming and import-alias conventions, the commit/branch model, and the real build/lint/type-check commands. Use this whenever working anywhere in this repository so changes match the codebase's actual conventions and pass CI.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works1822026년 10월 24일 업데이트

Use when a Task asks you to change an App Work — a running open-source application the owner forked, copied or linked into Ever Works — for example "add an SMS reminder", "fix the failed deployment of 3f9c2ab", or a Goal iteration or Mission Task filed on that App Work. Covers planning within the app's size guidance, respecting its protected paths and human-merge paths, running its declared checks, and writing a reviewable pull request against the branch the app deploys from.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ever-works/ever-works1822026년 10월 24일 업데이트

ever-works의 스킬 모두 보기

이 스킬의 문제 신고