Fix portal account creation and improve email handling
All checks were successful
Build And Push Image / docker (push) Successful in 2m56s
All checks were successful
Build And Push Image / docker (push) Successful in 2m56s
- Add explicit POST method to portal account creation API call - Improve error handling with specific messages for different failure cases - Remove SMTP verification step that was causing issues with some servers - Make email sending non-critical to portal account creation success - Add better response data handling for keycloak_id - Add integration review documentation
This commit is contained in:
@@ -117,12 +117,13 @@ export default defineEventHandler(async (event) => {
|
||||
await updateMember(memberId, { keycloak_id: keycloakId });
|
||||
|
||||
// 9. Send welcome/verification email using our custom email system
|
||||
console.log('[api/members/[id]/create-portal-account.post] Sending welcome/verification email...');
|
||||
console.log('[api/members/[id]/create-portal-account.post] Attempting to send welcome/verification email...');
|
||||
let emailSent = false;
|
||||
try {
|
||||
const { getEmailService } = await import('~/server/utils/email');
|
||||
const { generateEmailVerificationToken } = await import('~/server/utils/email-tokens');
|
||||
|
||||
const emailService = await getEmailService();
|
||||
const emailService = await getEmailService();
|
||||
const verificationToken = await generateEmailVerificationToken(keycloakId, member.email);
|
||||
const config = useRuntimeConfig();
|
||||
const verificationLink = `${config.public.domain}/api/auth/verify-email?token=${verificationToken}`;
|
||||
@@ -134,6 +135,7 @@ export default defineEventHandler(async (event) => {
|
||||
memberId: memberId
|
||||
});
|
||||
|
||||
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);
|
||||
@@ -144,12 +146,15 @@ export default defineEventHandler(async (event) => {
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'Portal account created successfully. The member will receive an email to verify their account and set their password.',
|
||||
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.',
|
||||
data: {
|
||||
keycloak_id: keycloakId,
|
||||
member_id: memberId,
|
||||
email: member.email,
|
||||
name: `${member.first_name} ${member.last_name}`
|
||||
name: `${member.first_name} ${member.last_name}`,
|
||||
email_sent: emailSent
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user