Skip to content

Commit b59e3f9

Browse files
committed
fix(events): Improve company email extraction logic for event registration
- Add defensive checks to handle both array and object company data structures - Extract company email from either array format or direct object property - Add console logging for debugging company data and extracted email values - Prevent potential undefined errors when accessing company email during registration flow
1 parent f1a6fde commit b59e3f9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/api/events/[slug]/register/route.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,17 @@ export async function POST(
125125
const { sendEventRegistrationEmails } = await import('@/lib/email/event-emails');
126126

127127
// Get company email if available
128-
const companyEmail = Array.isArray(event.companies) && event.companies.length > 0
129-
? event.companies[0]?.email
130-
: undefined;
128+
console.log('Event companies data:', event.companies);
129+
130+
let companyEmail: string | undefined;
131+
132+
if (Array.isArray(event.companies)) {
133+
companyEmail = event.companies[0]?.email;
134+
} else if (event.companies && typeof event.companies === 'object') {
135+
companyEmail = (event.companies as { email?: string }).email;
136+
}
137+
138+
console.log('Extracted company email:', companyEmail);
131139

132140
await sendEventRegistrationEmails({
133141
userEmail: user.email!,

0 commit comments

Comments
 (0)