Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Refactor email change confirmation flow to handle partner profiles

Kiran Ke3ab06c47493
diff --git a/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page-client.tsx b/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page-client.tsx
index 00dd8e182f..ff28702638 100644
--- a/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(auth)/auth/confirm-email-change/[token]/page-client.tsx
@@ -6,7 +6,11 @@ import { useRouter } from "next/navigation";
import { useEffect, useRef } from "react";
import { toast } from "sonner";
-export default async function ConfirmEmailChangePageClient() {
+export default async function ConfirmEmailChangePageClient({
+ isPartnerProfile,
+}: {
+ isPartnerProfile: boolean;
+}) {
const router = useRouter();
const { update, status } = useSession();
const hasUpdatedSession = useRef(false);
@@ -20,7 +24,7 @@ export default async function ConfirmEmailChangePageClient() {
hasUpdatedSession.current = true;
await update();
toast.success("Successfully updated your email!");
- router.replace("/account/settings");
+ router.replace(isPartnerProfile ? "/profile" : "/account/settings");
}
updateSession();
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.tsx
index bed8eb3727..f03c5cefc1 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
@@ -48,6 +48,7 @@ const VerifyEmailChange = async ({
},
});
+
if (!tokenFound || tokenFound.expires < new Date()) {
return (
<EmptyState
@@ -80,13 +81,18 @@ const VerifyEmailChange = async ({
redirect(`/login?next=/auth/confirm-email-change/${token}`);
}
- const { id: currentUserId, defaultPartnerId } = session.user;
+ const { id: userId, defaultPartnerId: partnerId } = session.user;
+
+ const identifier = "user_1K1A7E86362MHCHEMX11KHKQ8"
const data = await redis.get<{
email: string;
newEmail: string;
isPartnerProfile?: boolean;
- }>(`email-change-request:user:${currentUserId}`);
+ }>(`email-change-request:user:${identifier}`);
+
+ console.log({identifier})
+
if (!data) {
return (
@@ -102,7 +108,7 @@ const VerifyEmailChange = async ({
// Update the partner profile email
if (data.isPartnerProfile) {
- if (!defaultPartnerId) {
+ if (!partnerId) {
return (
<EmptyState
icon={InputPassword}
@@ -114,7 +120,7 @@ const VerifyEmailChange = async ({
await prisma.partner.update({
where: {
- id: defaultPartnerId,
+ id: partnerId,
},
data: {
email: data.newEmail,
@@ -126,7 +132,7 @@ const VerifyEmailChange = async ({
else {
user = await prisma.user.update({
where: {
- id: currentUserId,
+ id: userId,
},
data: {
email: data.newEmail,
@@ -159,11 +165,13 @@ const VerifyEmailChange = async ({
]),
);
- return <ConfirmEmailChangePageClient />;
+ return (
+ <ConfirmEmailChangePageClient isPartnerProfile={!!data.isPartnerProfile} />
+ );
};
const deleteRequest = async (tokenFound: VerificationToken) => {
- await Promise.all([
+ await Promise.allSettled([
prisma.verificationToken.delete({
where: {
token: tokenFound.token,