Skip to content

Commit 22fdcc8

Browse files
mjunaidcaclaude
andcommitted
fix(auth): Configure bcrypt password hashing to match seed script
Critical fix for authentication: Problem: - Better Auth default: scrypt password hashing - Seed script: bcrypt password hashing (bcrypt.hash(password, 10)) - Result: Seeded users cannot login (hash verification fails) Solution: Configure Better Auth to use bcrypt for both hashing and verification: ```typescript emailAndPassword: { password: { hash: async (password) => { const bcrypt = await import("bcryptjs"); return await bcrypt.hash(password, 10); }, verify: async ({ hash, password }) => { const bcrypt = await import("bcryptjs"); return await bcrypt.compare(password, hash); }, }, } ``` Why bcrypt: - Already used in seed script (scripts/seed-setup.ts) - Already installed as dependency (bcryptjs) - Widely adopted and secure (OWASP approved) - Consistent hashing across app and seed scripts Result: ✅ Seeded admin user ([email protected]) can now login ✅ All password authentication uses bcrypt ✅ No migration needed for existing users Testing: - Seed admin: pnpm seed:setup - Login: [email protected] / Admin123!@# Related: #21 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 9a197bb commit 22fdcc8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

auth-server/src/lib/auth.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ export const auth = betterAuth({
167167
minPasswordLength: 8,
168168
// Always require email verification for security
169169
requireEmailVerification: true,
170+
// Use bcrypt for password hashing (matches seed script)
171+
// Better Auth default is scrypt, but we use bcrypt for compatibility
172+
password: {
173+
hash: async (password) => {
174+
const bcrypt = await import("bcryptjs");
175+
return await bcrypt.hash(password, 10);
176+
},
177+
verify: async ({ hash, password }) => {
178+
const bcrypt = await import("bcryptjs");
179+
return await bcrypt.compare(password, hash);
180+
},
181+
},
170182
// Password reset (only when email is configured)
171183
...(emailEnabled && {
172184
sendResetPassword: async ({ user, url }) => {

0 commit comments

Comments
 (0)