fix(passkey): skip email verification in TEST_MODE for passkey registration

When TEST_MODE is enabled with autoVerifyUsers, passkey registration now
auto-verifies users immediately instead of sending verification emails.
This enables local development without SMTP configuration.
This commit is contained in:
Johannes Millan 2026-01-24 16:26:05 +01:00
parent c576372d00
commit e924b068ac

View file

@ -15,6 +15,7 @@ import { Logger } from './logger';
import { randomBytes } from 'crypto';
import { sendPasskeyRecoveryEmail } from './email';
import { Prisma } from '@prisma/client';
import { loadConfigFromEnv } from './config';
// Constants
const CHALLENGE_EXPIRY_MS = 5 * 60 * 1000; // 5 minutes
@ -240,7 +241,24 @@ export const verifyRegistration = async (
Logger.info(`Created new passkey user for ${email}`);
}
// Send verification email
// In TEST_MODE with autoVerifyUsers, skip email and auto-verify
const config = loadConfigFromEnv();
if (config.testMode?.autoVerifyUsers) {
await prisma.user.update({
where: { email: email.toLowerCase() },
data: {
isVerified: 1,
verificationToken: null,
verificationTokenExpiresAt: null,
},
});
Logger.info(`[TEST_MODE] Auto-verified passkey user: ${email}`);
return {
message: 'Registration successful. Your account has been automatically verified.',
};
}
// Normal flow: send verification email
const { sendVerificationEmail } = await import('./email');
const emailSent = await sendVerificationEmail(email, verificationToken);