Add forgot-password and reset-password flow

Users can now request a password reset link via email. Better Auth
sendResetPassword callback sends a branded email via Resend. Login
page shows success notice after password is set.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-07 11:04:06 +05:00
parent 93e74951a7
commit a5e7b20699
8 changed files with 280 additions and 4 deletions
+4 -1
View File
@@ -3,7 +3,7 @@ import { prismaAdapter } from "better-auth/adapters/prisma";
import { admin } from "better-auth/plugins";
import { prisma } from "./prisma";
import bcrypt from "bcryptjs";
import { sendWelcomeEmail } from "./email";
import { sendWelcomeEmail, sendPasswordResetEmail } from "./email";
export const auth = betterAuth({
database: prismaAdapter(prisma, {
@@ -16,6 +16,9 @@ export const auth = betterAuth({
hash: (password) => bcrypt.hash(password, 10),
verify: ({ hash, password }) => bcrypt.compare(password, hash),
},
sendResetPassword: async ({ user, url }) => {
await sendPasswordResetEmail(user.email, user.name, url);
},
},
databaseHooks: {
user: {