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.

Auto-verify website when website domain matches email domain

Steven Tey3bd5b47a97c9
diff --git a/apps/web/lib/actions/partners/start-partner-platform-verification.ts b/apps/web/lib/actions/partners/start-partner-platform-verification.ts
index c71dc4fc7c..c92824ff17 100644
--- a/apps/web/lib/actions/partners/start-partner-platform-verification.ts
+++ b/apps/web/lib/actions/partners/start-partner-platform-verification.ts
@@ -11,10 +11,15 @@ import {
sanitizeSocialHandle,
SOCIAL_PLATFORM_CONFIGS,
} from "@/lib/social-utils";
+import { PartnerProps } from "@/lib/types";
import { ratelimit } from "@/lib/upstash/ratelimit";
import { redis } from "@/lib/upstash/redis";
import { PlatformType } from "@dub/prisma/client";
-import { nanoid, PARTNERS_DOMAIN_WITH_NGROK } from "@dub/utils";
+import {
+ getDomainWithoutWWW,
+ nanoid,
+ PARTNERS_DOMAIN_WITH_NGROK,
+} from "@dub/utils";
import { cookies } from "next/headers";
import { v4 as uuid } from "uuid";
import * as z from "zod/v4";
@@ -29,10 +34,11 @@ const startPartnerPlatformVerificationSchema = z.object({
type VerificationResult =
| { type: "oauth"; oauthUrl: string }
| { type: "verification_code"; verificationCode: string }
- | { type: "txt_record"; websiteTxtRecord: string };
+ | { type: "txt_record"; websiteTxtRecord: string }
+ | { type: "auto_verified" };
type VerificationParams = {
- partnerId: string;
+ partner: Pick<PartnerProps, "id" | "email">;
platform: PlatformType;
handle: string;
source: "onboarding" | "settings";
@@ -63,7 +69,7 @@ export const startPartnerPlatformVerificationAction = authPartnerActionClient
}
const params: VerificationParams = {
- partnerId: partner.id,
+ partner,
platform,
handle,
source,
@@ -84,18 +90,40 @@ export const startPartnerPlatformVerificationAction = authPartnerActionClient
return startCodeVerification(params);
});
-// Start website verification using TXT record
+// Start website verification using TXT record (or auto-verify if email domain matches)
async function startWebsiteVerification({
- partnerId,
+ partner,
handle,
-}: Pick<VerificationParams, "partnerId" | "handle">): Promise<
- Extract<VerificationResult, { type: "txt_record" }>
+}: Pick<VerificationParams, "partner" | "handle">): Promise<
+ | Extract<VerificationResult, { type: "txt_record" }>
+ | Extract<VerificationResult, { type: "auto_verified" }>
> {
+ const websiteHostname = getDomainWithoutWWW(handle);
+
+ // Auto-verify if partner's email domain matches the website domain exactly
+ if (partner.email?.includes("@")) {
+ const emailDomain = partner.email.split("@")[1]?.toLowerCase();
+ if (emailDomain && emailDomain === websiteHostname) {
+ await upsertPartnerPlatform({
+ where: {
+ partnerId: partner.id,
+ type: "website",
+ },
+ data: {
+ identifier: handle,
+ verifiedAt: new Date(),
+ metadata: {},
+ },
+ });
+ return { type: "auto_verified" };
+ }
+ }
+
const websiteTxtRecord = `dub-domain-verification=${uuid()}`;
await upsertPartnerPlatform({
where: {
- partnerId,
+ partnerId: partner.id,
type: "website",
},
data: {
@@ -115,7 +143,7 @@ async function startWebsiteVerification({
// Start OAuth verification for platforms Twitter, TikTok and LinkedIn
async function startOAuthVerification({
- partnerId,
+ partner,
platform,
handle: rawHandle,
source,
@@ -142,7 +170,7 @@ async function startOAuthVerification({
// Store handle before OAuth redirect
await upsertPartnerPlatform({
where: {
- partnerId,
+ partnerId: partner.id,
type: platform,
},
data: {
@@ -157,7 +185,7 @@ async function startOAuthVerification({
`partnerSocialVerification:${state}`,
{
platform,
- partnerId,
+ partnerId: partner.id,
source,
},
{
@@ -200,10 +228,10 @@ async function startOAuthVerification({
// Start verification code flow for platforms like YouTube, Instagram
async function startCodeVerification({
- partnerId,
+ partner,
platform,
handle: rawHandle,
-}: Pick<VerificationParams, "partnerId" | "platform" | "handle">): Promise<
+}: Pick<VerificationParams, "partner" | "platform" | "handle">): Promise<
Extract<VerificationResult, { type: "verification_code" }>
> {
const platformConfig = SOCIAL_PLATFORM_CONFIGS[platform];
@@ -219,14 +247,14 @@ async function startCodeVerification({
}
const verificationCode = generateOTP();
- const cacheKey = `social-verification:${partnerId}:${platform}:${handle}`;
+ const cacheKey = `social-verification:${partner.id}:${platform}:${handle}`;
await redis.set(cacheKey, verificationCode, {
ex: 60 * 60 * 24, // 24 hours
});
await upsertPartnerPlatform({
where: {
- partnerId,
+ partnerId: partner.id,
type: platform,
},
data: {
diff --git a/apps/web/ui/partners/partner-platforms-form.tsx b/apps/web/ui/partners/partner-platforms-form.tsx
index af10532de9..3d91c8a9c4 100644
--- a/apps/web/ui/partners/partner-platforms-form.tsx
+++ b/apps/web/ui/partners/partner-platforms-form.tsx
@@ -154,11 +154,20 @@ export const PartnerPlatformsForm = forwardRef<
executeAsync: startSocialVerification,
isPending: isStartingSocialVerification,
} = useAction(startPartnerPlatformVerificationAction, {
- onSuccess: ({ input, data }) => {
+ onSuccess: async ({ input, data }) => {
if (!input || !data) {
return;
}
+ // For website: auto-verified when email domain matches website domain
+ if (data.type === "auto_verified") {
+ toast.success(
+ "Website automatically verified because your email domain matches the website domain.",
+ );
+ await mutate("/api/partner-profile");
+ return;
+ }
+
// For website verification (TXT record)
if (data.type === "txt_record") {
const websiteUrl = input.handle.startsWith("http")