Improve email verification error handling in registration and resend verification endpoints
Some checks failed
Build & Push Docker Image / build (push) Has been cancelled
Some checks failed
Build & Push Docker Image / build (push) Has been cancelled
This commit is contained in:
@@ -71,8 +71,13 @@ router.post('/register', async (req, res) => {
|
||||
try { appName = JSON.parse(brandingSetting.value).appName || appName; } catch {}
|
||||
}
|
||||
|
||||
sendVerificationEmail(email.toLowerCase(), display_name, verifyUrl, appName)
|
||||
.catch(err => console.error('Verification mail failed (non-fatal):', err.message));
|
||||
try {
|
||||
await sendVerificationEmail(email.toLowerCase(), display_name, verifyUrl, appName);
|
||||
} catch (mailErr) {
|
||||
console.error('Verification mail failed:', mailErr.message);
|
||||
// Account is created but email failed — user can resend from login page
|
||||
return res.status(201).json({ needsVerification: true, emailFailed: true, message: 'Account created but verification email could not be sent. Please try resending.' });
|
||||
}
|
||||
|
||||
return res.status(201).json({ needsVerification: true, message: 'Verification email has been sent' });
|
||||
}
|
||||
@@ -164,14 +169,17 @@ router.post('/resend-verification', async (req, res) => {
|
||||
try { appName = JSON.parse(brandingSetting.value).appName || appName; } catch {}
|
||||
}
|
||||
|
||||
// Fire-and-forget — do not await so SMTP timeouts don't fail the request
|
||||
sendVerificationEmail(email.toLowerCase(), user.display_name || user.name, verifyUrl, appName)
|
||||
.catch(err => console.error('Resend verification mail failed (non-fatal):', err.message));
|
||||
try {
|
||||
await sendVerificationEmail(email.toLowerCase(), user.display_name || user.name, verifyUrl, appName);
|
||||
} catch (mailErr) {
|
||||
console.error('Resend verification mail failed:', mailErr.message);
|
||||
return res.status(502).json({ error: 'Email could not be sent. Please check your SMTP configuration.' });
|
||||
}
|
||||
|
||||
res.json({ message: 'If an account exists, a new email has been sent.' });
|
||||
} catch (err) {
|
||||
console.error('Resend verification error:', err);
|
||||
res.status(500).json({ error: 'Email could not be sent' });
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user