fix(auth): move email verification config to correct location

Better Auth requires emailVerification config to be a separate top-level
option, not under emailAndPassword. Added sendOnSignUp: true to trigger
verification emails on registration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Till-JS 2026-01-26 15:54:35 +01:00
parent aa7f5fbb25
commit 14aaf01fa3

View file

@ -85,29 +85,13 @@ export function createBetterAuth(databaseUrl: string) {
},
}),
// Email/password authentication with email verification and password reset
// Email/password authentication with password reset
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
minPasswordLength: 8,
maxPasswordLength: 128,
/**
* Email Verification
*
* Sends verification email when user registers.
* User must verify email before they can log in.
*/
sendVerificationEmail: async ({
user,
url,
}: {
user: { email: string; name: string };
url: string;
}) => {
await sendVerificationEmail(user.email, url, user.name);
},
/**
* Password Reset Configuration
*
@ -128,6 +112,26 @@ export function createBetterAuth(databaseUrl: string) {
},
},
/**
* Email Verification Configuration
*
* Sends verification email when user registers.
* User must verify email before they can log in.
*/
emailVerification: {
sendOnSignUp: true,
autoSignInAfterVerification: true,
sendVerificationEmail: async ({
user,
url,
}: {
user: { email: string; name: string };
url: string;
}) => {
await sendVerificationEmail(user.email, url, user.name);
},
},
// Session configuration
session: {
expiresIn: 60 * 60 * 24 * 7, // 7 days