The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update unsubscribe-token.ts
Steven Tey06849cd11433
diff --git a/apps/web/lib/email/unsubscribe-token.ts b/apps/web/lib/email/unsubscribe-token.tsindex ab206796a1..ce597e7b9e 100644--- a/apps/web/lib/email/unsubscribe-token.ts+++ b/apps/web/lib/email/unsubscribe-token.ts@@ -1,6 +1,7 @@import { createHmac, timingSafeEqual } from "crypto";-const TOKEN_SECRET = process.env.UNSUBSCRIBE_TOKEN_SECRET;+const TOKEN_SECRET =+ process.env.UNSUBSCRIBE_TOKEN_SECRET || process.env.NEXTAUTH_SECRET;/*** Generate a secure unsubscribe token for an email address.@@ -12,7 +13,7 @@ export function generateUnsubscribeToken(email: string): string {const signature = createHmac("sha256", TOKEN_SECRET).update(email.toLowerCase()).digest("hex")- .slice(0, 16); // Truncate for shorter URLs+ .slice(0, 24); // Truncate for shorter URLs// Base64 encode the email and append the signatureconst encodedEmail = Buffer.from(email.toLowerCase()).toString("base64url");@@ -38,7 +39,7 @@ export function verifyUnsubscribeToken(token: string): string | null {const expectedSignature = createHmac("sha256", TOKEN_SECRET).update(email.toLowerCase()).digest("hex")- .slice(0, 16);+ .slice(0, 24);if (!timingSafeEqual(