The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Key email change Redis requests by token instead of user identifier.
Kiran K8e802414729b
diff --git a/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx b/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsxindex 8df0b38920..c7530b1453 100644--- a/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx+++ b/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page.tsx@@ -120,7 +120,7 @@ const VerifyEmailChange = async ({ params, searchParams }: PageProps) => {syncIdentity?: boolean;partnerId?: string;redirectTo?: "/profile" | "/account/settings";- }>(`email-change-request:user:${tokenIdentifier}`);+ }>(`email-change-request:token:${tokenFound.token}`);if (!data) {return (@@ -259,6 +259,6 @@ const deleteRequest = async (tokenFound: VerificationToken) => {},}),- redis.del(`email-change-request:user:${tokenFound.identifier}`),+ redis.del(`email-change-request:token:${tokenFound.token}`),]);};diff --git a/apps/web/lib/auth/request-email-change.ts b/apps/web/lib/auth/request-email-change.tsindex daf539dc54..ca3e1ecd41 100644--- a/apps/web/lib/auth/request-email-change.ts+++ b/apps/web/lib/auth/request-email-change.ts@@ -54,20 +54,21 @@ export const requestEmailChange = async ({});const token = randomBytes(32).toString("hex");+ const hashedToken = await hashToken(token, { secret: true });const expiresIn = 15 * 60 * 1000;// Create a new verification tokenawait prisma.verificationToken.create({data: {identifier,- token: await hashToken(token, { secret: true }),+ token: hashedToken,expires: new Date(Date.now() + expiresIn),},});// Set the email change request in Redis, we'll use this to verify the email change in /auth/confirm-email-change/[token]await redis.set(- `email-change-request:user:${identifier}`,+ `email-change-request:token:${hashedToken}`,{email,newEmail,