The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
code improvements
Pedro Ladeiraec657b9342f9
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsxindex 87d12e6d96..af92fd9361 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/profile-details-form.tsx@@ -305,7 +305,7 @@ function BasicInfoForm({mutatePrefix("/api/partner-profile");}, 0);- if (syncIdentity && !result.data.needsEmailVerification) {+ if (syncIdentity) {await updateSession();}};@@ -484,8 +484,7 @@ function BasicInfoForm({/></div><p className="text-xs text-neutral-500">- 3–30 characters. Lowercase letters, numbers, hyphens, and- underscores only.+ 3–30 characters. Lowercase letters, numbers, and hyphens only.</p></label>diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.tsindex c040378992..5247f63898 100644--- a/apps/web/app/api/user/route.ts+++ b/apps/web/app/api/user/route.ts@@ -145,6 +145,7 @@ export const PATCH = withSession(async ({ req, session }) => {currentEmail: session.user.email!,newEmail: email,userId: session.user.id,+ partnerId,hostName: PARTNERS_DOMAIN,redirectTo: "/account/settings",});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 abe3911465..71064e4ce9 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@@ -86,6 +86,7 @@ const VerifyEmailChange = async ({ params, searchParams }: PageProps) => {newEmail: string;isPartnerProfile?: boolean;syncIdentity?: boolean;+ partnerId?: string;redirectTo?: "/profile" | "/account/settings";}>(`email-change-request:user:${identifier}`);@@ -100,12 +101,34 @@ const VerifyEmailChange = async ({ params, searchParams }: PageProps) => {}if (data.syncIdentity) {- if (!partnerId) {+ const syncedPartnerId = data.partnerId;++ if (!syncedPartnerId) {return (<EmptyStateicon={InputPassword}- title="No Partner Profile Found"- description="We couldn't find a partner profile for your account. Please make sure you're logged in with the correct account at https://partners.dub.co"+ title="Invalid Token"+ description="This token is invalid. Please request a new one."+ />+ );+ }++ const partnerUser = await prisma.partnerUser.findUnique({+ where: {+ userId_partnerId: {+ userId,+ partnerId: syncedPartnerId,+ },+ },+ select: { userId: true },+ });++ if (!partnerUser) {+ return (+ <EmptyState+ icon={InputPassword}+ title="Unauthorized"+ description="You don't have access to update the partner profile associated with this email change request."/>);}@@ -121,7 +144,7 @@ const VerifyEmailChange = async ({ params, searchParams }: PageProps) => {}),prisma.partner.update({where: {- id: partnerId,+ id: syncedPartnerId,},data: {email: data.newEmail,diff --git a/apps/web/app/app.dub.co/(dashboard)/account/settings/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/account/settings/page-client.tsxindex cec7518e3f..641f26c0e1 100644--- a/apps/web/app/app.dub.co/(dashboard)/account/settings/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/account/settings/page-client.tsx@@ -84,7 +84,7 @@ function buildAccountSyncDescription(candidates: string[]) {export function SettingsPageClient() {const { data: session, update, status } = useSession();const { subdomain } = useCurrentSubdomain();- const isPartnerDomain = subdomain !== "app";+ const isPartnerDomain = subdomain === "partners";const { partner } = usePartnerProfile();const pendingPatchRef = useRef<PendingUserPatch | null>(null);const [syncDescription, setSyncDescription] = useState<ReactNode>("");diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.tsindex c6ef34dfca..9b7e9299eb 100644--- a/apps/web/lib/actions/partners/update-partner-profile.ts+++ b/apps/web/lib/actions/partners/update-partner-profile.ts@@ -196,6 +196,7 @@ export const updatePartnerProfileAction = authPartnerActionClientcurrentEmail: user.email!,newEmail,userId: user.id,+ partnerId: partner.id,hostName: PARTNERS_DOMAIN,redirectTo: "/profile",});diff --git a/apps/web/lib/auth/confirm-email-change.ts b/apps/web/lib/auth/confirm-email-change.tsindex fb6e1fe9dc..d496c194b3 100644--- a/apps/web/lib/auth/confirm-email-change.ts+++ b/apps/web/lib/auth/confirm-email-change.ts@@ -14,6 +14,7 @@ export const confirmEmailChange = async ({identifier,isPartnerProfile = false,syncIdentity = false,+ partnerId,redirectTo,hostName,}: {@@ -22,9 +23,17 @@ export const confirmEmailChange = async ({identifier: string;isPartnerProfile?: boolean; // If true, the email is being changed for a partner profilesyncIdentity?: boolean; // If true, update both user and partner email on confirm+ partnerId?: string;redirectTo?: "/profile" | "/account/settings";hostName: string;}) => {+ if (syncIdentity && !partnerId) {+ throw new DubApiError({+ code: "bad_request",+ message: "Partner ID is required when syncing identity.",+ });+ }+const { success } = await ratelimit(3, "1 d").limit(`email-change-request:${identifier}`,);@@ -63,7 +72,7 @@ export const confirmEmailChange = async ({email,newEmail,...(isPartnerProfile && { isPartnerProfile }),- ...(syncIdentity && { syncIdentity }),+ ...(syncIdentity && { syncIdentity, partnerId }),...(redirectTo && { redirectTo }),},{diff --git a/apps/web/lib/partners/sync-partner-identity.ts b/apps/web/lib/partners/sync-partner-identity.tsindex d771a7c329..2d80ca5c20 100644--- a/apps/web/lib/partners/sync-partner-identity.ts+++ b/apps/web/lib/partners/sync-partner-identity.ts@@ -32,9 +32,10 @@ export async function assertEmailAvailableForIdentitySync({}if (partnerWithEmail && partnerWithEmail.id !== partnerId) {- throw new Error(- `Email ${newEmail} is already in use. Do you want to merge your partner accounts instead? (https://d.to/merge-partners)`,- );+ throw new DubApiError({+ code: "conflict",+ message: `Email ${newEmail} is already in use. Do you want to merge your partner accounts instead? (https://d.to/merge-partners)`,+ });}}@@ -149,12 +150,14 @@ export async function requestSyncedEmailChange({currentEmail,newEmail,userId,+ partnerId,hostName,redirectTo,}: {currentEmail: string;newEmail: string;userId: string;+ partnerId: string;hostName: string;redirectTo: "/profile" | "/account/settings";}) {@@ -164,6 +167,7 @@ export async function requestSyncedEmailChange({identifier: userId,hostName,syncIdentity: true,+ partnerId,redirectTo,});}diff --git a/apps/web/ui/modals/confirm-modal.tsx b/apps/web/ui/modals/confirm-modal.tsxindex fc0791cefc..cb42500ef6 100644--- a/apps/web/ui/modals/confirm-modal.tsx+++ b/apps/web/ui/modals/confirm-modal.tsx@@ -41,6 +41,8 @@ function ConfirmModal({const [isLoading, setIsLoading] = useState(false);const handleConfirm = async () => {+ if (isLoading) return;+setIsLoading(true);try {await onConfirm();@@ -50,6 +52,18 @@ function ConfirmModal({}};+ const handleCancel = async () => {+ if (isLoading) return;++ setIsLoading(true);+ try {+ await onCancel?.();+ setShowConfirmModal(false);+ } finally {+ setIsLoading(false);+ }+ };+return (<ModalshowModal={showConfirmModal}@@ -76,15 +90,8 @@ function ConfirmModal({variant="secondary"className="h-8 w-fit"text={cancelText}- onClick={async () => {- setIsLoading(true);- try {- await onCancel?.();- setShowConfirmModal(false);- } finally {- setIsLoading(false);- }- }}+ disabled={isLoading}+ onClick={handleCancel}/><Buttonvariant={confirmVariant}