fix: AWS SES configuration and email verification flow
Changes: - Updated AWS_REGION to eu-central-1 in env examples - Fixed email verification to return new JWT token with updated emailVerified status - Added updateUser function to AuthContext for token refresh - Updated frontend to save new token after email verification - Fixed variable naming conflict (token vs jwtToken) in verification endpoints - Changed WSDC ID placeholder from 26997 to 12345 This ensures the verification banner disappears immediately after email verification without requiring re-login.
This commit is contained in:
@@ -21,8 +21,8 @@ JWT_EXPIRES_IN=24h
|
||||
# AWS SES - Production credentials
|
||||
# BEST PRACTICE: Use IAM roles instead of access keys
|
||||
AWS_REGION=us-east-1
|
||||
AWS_ACCESS_KEY_ID=AKIASOH3DHHDA557Z5N7
|
||||
AWS_SECRET_ACCESS_KEY=XZvSdqgL/tqSJ6AUE21l4DrU422AV/bo5wHdLfoR
|
||||
AWS_ACCESS_KEY_ID=AK.........
|
||||
AWS_SECRET_ACCESS_KEY=change-it
|
||||
SES_FROM_EMAIL=noreply@spotlight.cam
|
||||
SES_FROM_NAME=spotlight.cam
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ async function verifyEmailByToken(req, res, next) {
|
||||
}
|
||||
|
||||
// Update user - mark as verified and clear tokens
|
||||
await prisma.user.update({
|
||||
const updatedUser = await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: {
|
||||
emailVerified: true,
|
||||
@@ -208,9 +208,19 @@ async function verifyEmailByToken(req, res, next) {
|
||||
console.error('Failed to send welcome email:', emailError);
|
||||
}
|
||||
|
||||
// Generate new JWT token with updated emailVerified status
|
||||
const jwtToken = generateToken({ userId: updatedUser.id });
|
||||
|
||||
// Remove sensitive data
|
||||
const { passwordHash, verificationToken, verificationCode, verificationTokenExpiry, resetToken, resetTokenExpiry, ...userWithoutPassword } = updatedUser;
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Email verified successfully!',
|
||||
data: {
|
||||
user: userWithoutPassword,
|
||||
token: jwtToken,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
@@ -261,7 +271,7 @@ async function verifyEmailByCode(req, res, next) {
|
||||
}
|
||||
|
||||
// Update user - mark as verified and clear tokens
|
||||
await prisma.user.update({
|
||||
const updatedUser = await prisma.user.update({
|
||||
where: { id: user.id },
|
||||
data: {
|
||||
emailVerified: true,
|
||||
@@ -278,9 +288,19 @@ async function verifyEmailByCode(req, res, next) {
|
||||
console.error('Failed to send welcome email:', emailError);
|
||||
}
|
||||
|
||||
// Generate new JWT token with updated emailVerified status
|
||||
const jwtToken = generateToken({ userId: updatedUser.id });
|
||||
|
||||
// Remove sensitive data
|
||||
const { passwordHash, verificationToken, verificationCode, verificationTokenExpiry, resetToken, resetTokenExpiry, ...userWithoutPassword } = updatedUser;
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
message: 'Email verified successfully!',
|
||||
data: {
|
||||
user: userWithoutPassword,
|
||||
token: jwtToken,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
Reference in New Issue
Block a user