Add JWT configuration and improve email error handling
All checks were successful
Build And Push Image / docker (push) Successful in 2m51s
All checks were successful
Build And Push Image / docker (push) Successful in 2m51s
- Add jwtSecret to runtime config with fallback to sessionSecret - Enhance email error tracking in portal account creation API - Fix jsonwebtoken imports and improve type safety - Include detailed email error information in API responses
This commit is contained in:
@@ -119,6 +119,8 @@ export default defineEventHandler(async (event) => {
|
||||
// 9. Send welcome/verification email using our custom email system
|
||||
console.log('[api/members/[id]/create-portal-account.post] Attempting to send welcome/verification email...');
|
||||
let emailSent = false;
|
||||
let emailError: string | null = null;
|
||||
|
||||
try {
|
||||
const { getEmailService } = await import('~/server/utils/email');
|
||||
const { generateEmailVerificationToken } = await import('~/server/utils/email-tokens');
|
||||
@@ -137,8 +139,13 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
emailSent = true;
|
||||
console.log('[api/members/[id]/create-portal-account.post] Welcome email sent successfully');
|
||||
} catch (emailError: any) {
|
||||
console.error('[api/members/[id]/create-portal-account.post] Failed to send welcome email:', emailError.message);
|
||||
} catch (error: any) {
|
||||
emailError = error.message || 'Unknown email error';
|
||||
console.error('[api/members/[id]/create-portal-account.post] Failed to send welcome email:', emailError);
|
||||
|
||||
// Log the full error for debugging
|
||||
console.error('[api/members/[id]/create-portal-account.post] Full email error:', error);
|
||||
|
||||
// Don't fail the account creation if email fails - user can resend verification email later
|
||||
}
|
||||
|
||||
@@ -148,13 +155,14 @@ export default defineEventHandler(async (event) => {
|
||||
success: true,
|
||||
message: emailSent
|
||||
? 'Portal account created successfully. The member will receive an email to verify their account and set their password.'
|
||||
: 'Portal account created successfully. Email sending is not configured - the member will need to request a password reset to access their account.',
|
||||
: `Portal account created successfully. Email sending failed: ${emailError || 'Unknown error'}. The member can use "Forgot Password" to access their account.`,
|
||||
data: {
|
||||
keycloak_id: keycloakId,
|
||||
member_id: memberId,
|
||||
email: member.email,
|
||||
name: `${member.first_name} ${member.last_name}`,
|
||||
email_sent: emailSent
|
||||
email_sent: emailSent,
|
||||
email_error: emailError
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user