Fix email links using relative paths — prepend baseUrl for absolute URLs
All checks were successful
Build and Push Docker Image / build (push) Successful in 8m49s

Relative linkUrl paths (e.g. /jury/competitions) were passed as-is to
email templates, causing email clients to interpret them as local file
protocols (x-webdoc:// on macOS). Now prepends NEXTAUTH_URL to any
relative path before sending.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt
2026-02-19 13:45:20 +01:00
parent baca483fcb
commit c62a335424

View File

@@ -426,6 +426,10 @@ async function maybeSendEmailWithSetting(
return return
} }
// Ensure linkUrl is absolute for emails (relative paths break in email clients)
const baseUrl = process.env.NEXTAUTH_URL || 'https://portal.monaco-opc.com'
const absoluteLinkUrl = linkUrl && linkUrl.startsWith('/') ? `${baseUrl}${linkUrl}` : linkUrl
await sendStyledNotificationEmail( await sendStyledNotificationEmail(
user.email, user.email,
user.name || 'User', user.name || 'User',
@@ -433,7 +437,7 @@ async function maybeSendEmailWithSetting(
{ {
title, title,
message, message,
linkUrl, linkUrl: absoluteLinkUrl,
metadata, metadata,
}, },
emailSetting.emailSubject || undefined emailSetting.emailSubject || undefined