Mostra il link di disiscrizione dopo la conferma newsletter.
Passa il token unsub alla pagina di conferma e lo include anche nell'email di double opt-in. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -79,5 +79,8 @@ export const GET: APIRoute = async ({ request, locals, url }) => {
|
||||
}
|
||||
}
|
||||
|
||||
return Response.redirect(new URL(okPath, request.url).toString(), 303);
|
||||
return Response.redirect(
|
||||
new URL(`${okPath}?unsub=${encodeURIComponent(row.unsubscribe_token)}`, request.url).toString(),
|
||||
303,
|
||||
);
|
||||
};
|
||||
|
||||
@ -18,7 +18,11 @@ import {
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string; text: string } {
|
||||
function confirmEmailCopy(
|
||||
locale: string,
|
||||
confirmUrl: string,
|
||||
unsubscribeUrl: string,
|
||||
): { subject: string; text: string } {
|
||||
if (locale === 'en') {
|
||||
return {
|
||||
subject: 'Confirm your NexStudio newsletter subscription',
|
||||
@ -29,6 +33,9 @@ function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string
|
||||
confirmUrl,
|
||||
'',
|
||||
'If you did not request this, you can ignore this message.',
|
||||
'',
|
||||
'Unsubscribe:',
|
||||
unsubscribeUrl,
|
||||
].join('\n'),
|
||||
};
|
||||
}
|
||||
@ -42,6 +49,9 @@ function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string
|
||||
confirmUrl,
|
||||
'',
|
||||
'หากคุณไม่ได้ขอสมัคร สามารถเพิกเฉยต่อข้อความนี้ได้',
|
||||
'',
|
||||
'ยกเลิกการสมัคร:',
|
||||
unsubscribeUrl,
|
||||
].join('\n'),
|
||||
};
|
||||
}
|
||||
@ -54,6 +64,9 @@ function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string
|
||||
confirmUrl,
|
||||
'',
|
||||
'Se non hai richiesto l’iscrizione, puoi ignorare questo messaggio.',
|
||||
'',
|
||||
'Per disiscriverti:',
|
||||
unsubscribeUrl,
|
||||
].join('\n'),
|
||||
};
|
||||
}
|
||||
@ -102,6 +115,10 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
const unsubscribeToken = createToken();
|
||||
const origin = siteOrigin(url, runtimeEnv);
|
||||
const confirmUrl = absoluteUrl(origin, `/api/newsletter/confirm?token=${confirmToken}`);
|
||||
const unsubscribeUrl = absoluteUrl(
|
||||
origin,
|
||||
`/api/newsletter/unsubscribe?token=${unsubscribeToken}`,
|
||||
);
|
||||
|
||||
if (mode !== 'live') {
|
||||
console.info('[newsletter:dev] Subscription request', {
|
||||
@ -170,7 +187,7 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
||||
.run();
|
||||
}
|
||||
|
||||
const copy = confirmEmailCopy(locale, confirmUrl);
|
||||
const copy = confirmEmailCopy(locale, confirmUrl, unsubscribeUrl);
|
||||
try {
|
||||
await sendCloudflareEmail(emailBinding, {
|
||||
fromEmail,
|
||||
|
||||
Reference in New Issue
Block a user