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.

address CR feedback, harden

Steven Teyfe83ea144d0f
diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.ts
index 6fb8e3980b..2dd3049a8a 100644
--- a/apps/web/lib/actions/send-otp.ts
+++ b/apps/web/lib/actions/send-otp.ts
@@ -39,10 +39,10 @@ export const sendOtpAction = actionClient
}
const isGenericEmailWithPlus = email.includes("+") && isGenericEmail(email);
- const domainBlocked = await isEmailDomainBlocked(email);
+ const emailDomainBlocked = await isEmailDomainBlocked(email);
// if any of the flags match, run one final edge case check, before throwing an error
- if (isGenericEmailWithPlus || domainBlocked) {
+ if (isGenericEmailWithPlus || emailDomainBlocked) {
// edge case: the user already has a partner account on Dub with this email address,
// or they have an existing application for a program, we can allow them to continue
const [isPartnerAccount, hasExistingApplications] = await Promise.all([
diff --git a/apps/web/lib/auth/request-email-change.ts b/apps/web/lib/auth/request-email-change.ts
index 48ee1bd9dd..cb34a443e1 100644
--- a/apps/web/lib/auth/request-email-change.ts
+++ b/apps/web/lib/auth/request-email-change.ts
@@ -6,6 +6,7 @@ import { randomBytes } from "crypto";
import { hashToken } from ".";
import { DubApiError } from "../api/errors";
import { isEmailDomainBlocked } from "../email/is-email-domain-blocked";
+import { isGenericEmail } from "../is-generic-email";
import { ratelimit, redis } from "../upstash";
// Send the OTP to confirm the email address change for existing users/partners
@@ -35,14 +36,6 @@ export const requestEmailChange = async ({
});
}
- if (await isEmailDomainBlocked(newEmail)) {
- throw new DubApiError({
- code: "bad_request",
- message:
- "Invalid email address – please use your work email instead. If you think this is a mistake, please contact us at dub.co/support",
- });
- }
-
const { success } = await ratelimit(3, "1 d").limit(
`email-change-request:${identifier}`,
);
@@ -55,6 +48,16 @@ export const requestEmailChange = async ({
});
}
+ const isGenericEmailWithPlus = email.includes("+") && isGenericEmail(email);
+ const emailDomainBlocked = await isEmailDomainBlocked(newEmail);
+ if (isGenericEmailWithPlus || emailDomainBlocked) {
+ throw new DubApiError({
+ code: "bad_request",
+ message:
+ "Invalid email address – please use your work email instead. If you think this is a mistake, please contact us at dub.co/support",
+ });
+ }
+
// Remove existing verification tokens
await prisma.verificationToken.deleteMany({
where: {