The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix sendOtpAction logic
Steven Teye48101056421
diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex 81f7494510..ac8c3dc3b3 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -140,9 +140,6 @@ PLAIN_WEBHOOK_SECRET=###### DUB.CO INTERNAL USE ONLY ############################################-# For the official Dub app-NEXT_PUBLIC_IS_DUB=-# For storing vector embeddings (/api/support/chat)UPSTASH_VECTOR_REST_URL=UPSTASH_VECTOR_REST_TOKEN=diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.tsindex a70d2d5512..ed977276d6 100644--- a/apps/web/lib/actions/send-otp.ts+++ b/apps/web/lib/actions/send-otp.ts@@ -38,56 +38,52 @@ export const sendOtpAction = actionClientthrow new Error("Too many requests. Please try again later.");}- if (email.includes("+") && isGenericEmail(email)) {- throw new Error(- "Email addresses with + are not allowed. Please use your work email instead.",- );- }+ const isGenericEmailWithPlus = email.includes("+") && isGenericEmail(email);- const domain = email.split("@")[1];+ const emailDomain = email.split("@")[1];- if (process.env.NEXT_PUBLIC_IS_DUB) {- const [isDisposable, emailDomainTerms] = await Promise.all([- redis.sismember("disposableEmailDomains", domain),- process.env.EDGE_CONFIG ? get("emailDomainTerms") : [],- ]);+ const [isDisposable, emailDomainTerms] = await Promise.all([+ redis.sismember("disposableEmailDomains", emailDomain),+ process.env.EDGE_CONFIG ? get("emailDomainTerms") : [],+ ]);- // Only build the regex if we have at least one term; otherwise set to null- const blacklistedEmailDomainTermsRegex =- emailDomainTerms && Array.isArray(emailDomainTerms)- ? new RegExp(- emailDomainTerms- .map((term: string) =>- term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),- ) // replace special characters with escape sequences- .join("|"),- )- : null;-- if (- isDisposable ||- (blacklistedEmailDomainTermsRegex &&- blacklistedEmailDomainTermsRegex.test(domain))- ) {- // 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([- prisma.partner.findUnique({- where: {- email,- },- }),- prisma.programApplication.findFirst({- where: {- email,- },- }),- ]);- if (!isPartnerAccount && !hasExistingApplications) {- throw new Error(- "Invalid email address – please use your work email instead. If you think this is a mistake, please contact us at dub.co/support",- );- }+ // Only build the regex if we have at least one term; otherwise set to null+ const blacklistedEmailDomainTermsRegex =+ emailDomainTerms && Array.isArray(emailDomainTerms)+ ? new RegExp(+ emailDomainTerms+ .map((term: string) =>+ term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),+ ) // replace special characters with escape sequences+ .join("|"),+ )+ : null;++ // if any of the flags match, run one final edge case check, before throwing an error+ if (+ isGenericEmailWithPlus ||+ isDisposable ||+ (blacklistedEmailDomainTermsRegex &&+ blacklistedEmailDomainTermsRegex.test(emailDomain))+ ) {+ // 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([+ prisma.partner.findUnique({+ where: {+ email,+ },+ }),+ prisma.programApplication.findFirst({+ where: {+ email,+ },+ }),+ ]);+ if (!isPartnerAccount && !hasExistingApplications) {+ throw new Error(+ "Invalid email address – please use your work email instead. If you think this is a mistake, please contact us at dub.co/support",+ );}}diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.tsindex f94b1f8ceb..af7655fa43 100644--- a/apps/web/lib/analytics/get-analytics.ts+++ b/apps/web/lib/analytics/get-analytics.ts@@ -70,8 +70,8 @@ export const getAnalytics = async (params: AnalyticsFilters) => {: `SUM(${event}) as ${event}`;const response = await conn.execute(- `SELECT ${aggregateColumns} FROM Link WHERE id IN (${linkIdPlaceholders})`,- normalizedLinkId.values,+ `SELECT ${aggregateColumns} FROM Link WHERE id IN (${linkIdPlaceholders}) AND projectId = ?`,+ [...normalizedLinkId.values, workspaceId],);return analyticsResponse["count"].parse(response.rows[0]);diff --git a/apps/web/lib/api/links/utils/key-checks.ts b/apps/web/lib/api/links/utils/key-checks.tsindex 3be0fa6850..cc34e7fdf1 100644--- a/apps/web/lib/api/links/utils/key-checks.ts+++ b/apps/web/lib/api/links/utils/key-checks.ts@@ -41,7 +41,7 @@ export async function keyChecks({};}- if (isDubDomain(domain) && process.env.NEXT_PUBLIC_IS_DUB) {+ if (isDubDomain(domain)) {if (domain === "dub.sh" || domain === "dub.link") {if (DEFAULT_REDIRECTS[key] || RESERVED_SLUGS.includes(key)) {return {diff --git a/apps/web/lib/edge-config/get-feature-flags.ts b/apps/web/lib/edge-config/get-feature-flags.tsindex ce05812779..02fb582043 100644--- a/apps/web/lib/edge-config/get-feature-flags.ts+++ b/apps/web/lib/edge-config/get-feature-flags.ts@@ -19,7 +19,7 @@ export const getFeatureFlags = async ({analyticsSettingsSiteVisitTracking: false,};- if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ if (!process.env.EDGE_CONFIG) {// return all features as true if edge config is not availablereturn Object.fromEntries(Object.entries(workspaceFeatures).map(([key, _v]) => [key, true]),diff --git a/apps/web/lib/edge-config/is-blacklisted-domain.ts b/apps/web/lib/edge-config/is-blacklisted-domain.tsindex 1c71a12fed..fed6970524 100644--- a/apps/web/lib/edge-config/is-blacklisted-domain.ts+++ b/apps/web/lib/edge-config/is-blacklisted-domain.ts@@ -1,7 +1,7 @@import { getAll } from "@vercel/edge-config";export const isBlacklistedDomain = async (domain: string): Promise<boolean> => {- if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ if (!process.env.EDGE_CONFIG) {return false;}diff --git a/apps/web/lib/edge-config/is-blacklisted-email.ts b/apps/web/lib/edge-config/is-blacklisted-email.tsindex 52aa985331..434e5ee27f 100644--- a/apps/web/lib/edge-config/is-blacklisted-email.ts+++ b/apps/web/lib/edge-config/is-blacklisted-email.ts@@ -1,7 +1,7 @@import { get } from "@vercel/edge-config";export const isBlacklistedEmail = async (email: string | string[]) => {- if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ if (!process.env.EDGE_CONFIG) {return false;}diff --git a/apps/web/lib/edge-config/is-blacklisted-key.ts b/apps/web/lib/edge-config/is-blacklisted-key.tsindex 86fae891ad..976e2d0087 100644--- a/apps/web/lib/edge-config/is-blacklisted-key.ts+++ b/apps/web/lib/edge-config/is-blacklisted-key.ts@@ -1,7 +1,7 @@import { get } from "@vercel/edge-config";export const isBlacklistedKey = async (key: string) => {- if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ if (!process.env.EDGE_CONFIG) {return false;}diff --git a/apps/web/lib/edge-config/is-blacklisted-referrer.ts b/apps/web/lib/edge-config/is-blacklisted-referrer.tsindex b1b530ae17..5741e5ea80 100644--- a/apps/web/lib/edge-config/is-blacklisted-referrer.ts+++ b/apps/web/lib/edge-config/is-blacklisted-referrer.ts@@ -2,7 +2,7 @@ import { getDomainWithoutWWW } from "@dub/utils";import { get } from "@vercel/edge-config";export const isBlacklistedReferrer = async (referrer: string | null) => {- if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ if (!process.env.EDGE_CONFIG) {return false;}diff --git a/apps/web/lib/edge-config/is-reserved-username.ts b/apps/web/lib/edge-config/is-reserved-username.tsindex 48a4e23a66..9b9fc45876 100644--- a/apps/web/lib/edge-config/is-reserved-username.ts+++ b/apps/web/lib/edge-config/is-reserved-username.ts@@ -5,7 +5,7 @@ import { get } from "@vercel/edge-config";* Check if a username is reserved – should only be available on Pro+*/export const isReservedUsername = async (key: string) => {- if (!process.env.NEXT_PUBLIC_IS_DUB || !process.env.EDGE_CONFIG) {+ if (!process.env.EDGE_CONFIG) {return false;}diff --git a/packages/utils/src/constants/dub-domains.ts b/packages/utils/src/constants/dub-domains.tsindex 10a33eebd7..f53afec733 100644--- a/packages/utils/src/constants/dub-domains.ts+++ b/packages/utils/src/constants/dub-domains.ts@@ -12,133 +12,125 @@ export const DUB_DOMAINS = [description: "The default domain for all new accounts.",projectId: DUB_WORKSPACE_ID,},- ...(process.env.NEXT_PUBLIC_IS_DUB- ? [- {- id: "clce1z7cs00y8rbstk4xtnj0k",- slug: "chatg.pt",- verified: true,- primary: false,- archived: false,- placeholder: "https://chat.openai.com/g/g-UGjKKONEe-domainsgpt",- allowedHostnames: ["openai.com", "chatgpt.com"],- description:- "Branded domain for ChatGPT links (convos, custom GPTs).",- projectId: DUB_WORKSPACE_ID,- },- {- id: "cloxw8y2u0003js08a7mqg1j8",- slug: "spti.fi",- verified: true,- primary: false,- archived: false,- placeholder: "https://open.spotify.com/album/1SCyi9a5pOasikidToUY5y",- allowedHostnames: ["spotify.com"],- description:- "Branded domain for Spotify links (songs, playlists, etc.).",- projectId: DUB_WORKSPACE_ID,- },- {- id: "cltgtd6s5000341itdszz20u2",- slug: "git.new",- verified: true,- primary: false,- archived: false,- placeholder: "https://github.com/dubinc/dub",- allowedHostnames: ["github.com"],- description:- "Branded domain for GitHub links (repositories, gists, etc.).",- projectId: DUB_WORKSPACE_ID,- },- {- id: "cm23qevp4000412mqwvtkthzw",- slug: "cal.link",- verified: true,- primary: false,- archived: false,- placeholder: "https://cal.com/steven",- allowedHostnames: [- "app.acuityscheduling.com",- "app.apollo.io",- "cal.com",- "calendly.com",- "calendar.app.google",- "calendar.google.com",- "calendar.notion.so",- "chilipiper.com",- "fantastical.app",- "fillout.com",- "hubspot.com",- "mentordeck.com",- "savvycal.com",- "scheduler.default.com",- "tidycal.com",- "you.ashbyhq.com",- "zcal.co",- ],- description:- "Branded domain for your scheduling links (Cal.com, Calendly, etc.).",- projectId: DUB_WORKSPACE_ID,- },- {- id: "cloxw8qtk000bjt08n9b812vs",- slug: "amzn.id",- verified: true,- primary: false,- archived: false,- placeholder: "https://www.amazon.com/dp/B0BW4SWNC8",- allowedHostnames: [- "amazon.com",- "amazon.co.uk",- "amazon.ca",- "amazon.es",- "amazon.fr",- ],- description:- "Branded domain for Amazon links (products, wishlists, etc.).",- projectId: DUB_WORKSPACE_ID,- },- {- id: "clymd6zkc0001elilr1215tj9",- slug: "ggl.link",- verified: true,- primary: false,- archived: false,- placeholder:- "https://docs.google.com/document/d/15-GOZA12SXGEh8lNwU5QI1jBi04TCPgY2-LChTbXVpA",- allowedHostnames: [- "google.com",- "google.co.uk",- "google.co.id",- "google.ca",- "google.es",- "google.fr",- "googleblog.com",- "blog.google",- "g.co",- "g.page",- "youtube.com",- "youtu.be",- ],- description:- "Branded domain for Google links (Search, Docs, Sheets, Slides, Drive, Maps, etc.).",- projectId: DUB_WORKSPACE_ID,- },- {- id: "clymczttm0001jgkore3ltr37",- slug: "fig.page",- verified: true,- primary: false,- archived: false,- placeholder:- "https://www.figma.com/design/YAfTk6SGV2HcSvL2415oED/Dub.co-Brand-Assets-(Public)?node-id=1-36593&t=QMKQNtUzxSSzG3hX-1",- allowedHostnames: ["figma.com"],- description:- "Branded domain for Figma links (portfolios, prototypes, presentations, etc.).",- projectId: DUB_WORKSPACE_ID,- },- ]- : []),+ {+ id: "clce1z7cs00y8rbstk4xtnj0k",+ slug: "chatg.pt",+ verified: true,+ primary: false,+ archived: false,+ placeholder: "https://chat.openai.com/g/g-UGjKKONEe-domainsgpt",+ allowedHostnames: ["openai.com", "chatgpt.com"],+ description: "Branded domain for ChatGPT links (convos, custom GPTs).",+ projectId: DUB_WORKSPACE_ID,+ },+ {+ id: "cloxw8y2u0003js08a7mqg1j8",+ slug: "spti.fi",+ verified: true,+ primary: false,+ archived: false,+ placeholder: "https://open.spotify.com/album/1SCyi9a5pOasikidToUY5y",+ allowedHostnames: ["spotify.com"],+ description: "Branded domain for Spotify links (songs, playlists, etc.).",+ projectId: DUB_WORKSPACE_ID,+ },+ {+ id: "cltgtd6s5000341itdszz20u2",+ slug: "git.new",+ verified: true,+ primary: false,+ archived: false,+ placeholder: "https://github.com/dubinc/dub",+ allowedHostnames: ["github.com"],+ description: "Branded domain for GitHub links (repositories, gists, etc.).",+ projectId: DUB_WORKSPACE_ID,+ },+ {+ id: "cm23qevp4000412mqwvtkthzw",+ slug: "cal.link",+ verified: true,+ primary: false,+ archived: false,+ placeholder: "https://cal.com/steven",+ allowedHostnames: [+ "app.acuityscheduling.com",+ "app.apollo.io",+ "cal.com",+ "calendly.com",+ "calendar.app.google",+ "calendar.google.com",+ "calendar.notion.so",+ "chilipiper.com",+ "fantastical.app",+ "fillout.com",+ "hubspot.com",+ "mentordeck.com",+ "savvycal.com",+ "scheduler.default.com",+ "tidycal.com",+ "you.ashbyhq.com",+ "zcal.co",+ ],+ description:+ "Branded domain for your scheduling links (Cal.com, Calendly, etc.).",+ projectId: DUB_WORKSPACE_ID,+ },+ {+ id: "cloxw8qtk000bjt08n9b812vs",+ slug: "amzn.id",+ verified: true,+ primary: false,+ archived: false,+ placeholder: "https://www.amazon.com/dp/B0BW4SWNC8",+ allowedHostnames: [+ "amazon.com",+ "amazon.co.uk",+ "amazon.ca",+ "amazon.es",+ "amazon.fr",+ ],+ description: "Branded domain for Amazon links (products, wishlists, etc.).",+ projectId: DUB_WORKSPACE_ID,+ },+ {+ id: "clymd6zkc0001elilr1215tj9",+ slug: "ggl.link",+ verified: true,+ primary: false,+ archived: false,+ placeholder:+ "https://docs.google.com/document/d/15-GOZA12SXGEh8lNwU5QI1jBi04TCPgY2-LChTbXVpA",+ allowedHostnames: [+ "google.com",+ "google.co.uk",+ "google.co.id",+ "google.ca",+ "google.es",+ "google.fr",+ "googleblog.com",+ "blog.google",+ "g.co",+ "g.page",+ "youtube.com",+ "youtu.be",+ ],+ description:+ "Branded domain for Google links (Search, Docs, Sheets, Slides, Drive, Maps, etc.).",+ projectId: DUB_WORKSPACE_ID,+ },+ {+ id: "clymczttm0001jgkore3ltr37",+ slug: "fig.page",+ verified: true,+ primary: false,+ archived: false,+ placeholder:+ "https://www.figma.com/design/YAfTk6SGV2HcSvL2415oED/Dub.co-Brand-Assets-(Public)?node-id=1-36593&t=QMKQNtUzxSSzG3hX-1",+ allowedHostnames: ["figma.com"],+ description:+ "Branded domain for Figma links (portfolios, prototypes, presentations, etc.).",+ projectId: DUB_WORKSPACE_ID,+ },];export const DUB_DOMAINS_ARRAY = DUB_DOMAINS.map((domain) => domain.slug);