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.

WIP domain verification

Tim Wilsondec393046d60
diff --git a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx
index 8ed52bab80..bcb6d0129a 100644
--- a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx
+++ b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/online-presence-form.tsx
@@ -1,11 +1,12 @@
"use client";
import { updateOnlinePresenceAction } from "@/lib/actions/partners/update-online-presence";
+import { DomainVerificationModal } from "@/ui/modals/domain-verification-modal";
import { Button, Globe, Instagram, TikTok, Twitter, YouTube } from "@dub/ui";
import { cn } from "@dub/utils/src/functions";
import { useAction } from "next-safe-action/hooks";
import { useRouter } from "next/navigation";
-import { useRef } from "react";
+import { useState } from "react";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
import { z } from "zod";
@@ -40,7 +41,10 @@ export function OnlinePresenceForm({
const {
register,
setError,
+ watch,
+ getValues,
handleSubmit,
+ getFieldState,
formState: { errors, isSubmitting, isSubmitSuccessful },
} = useForm<OnlinePresenceFormData>({
defaultValues: {
@@ -52,9 +56,14 @@ export function OnlinePresenceForm({
},
});
+ const website = watch("website");
+
const { executeAsync } = useAction(updateOnlinePresenceAction, {
- onSuccess: () => {
- router.push(country === "US" ? "/onboarding/verify" : "/programs");
+ onSuccess: (result) => {
+ if (!result?.data?.success)
+ setError("root.serverError", {
+ message: "Failed to update online presence",
+ });
},
onError: ({ error }) => {
if (error.serverError) {
@@ -69,163 +78,215 @@ export function OnlinePresenceForm({
},
});
- const formRef = useRef<HTMLFormElement>(null);
+ const [domainVerificationData, setDomainVerificationData] = useState<{
+ domain: string;
+ txtRecord: string;
+ } | null>(null);
+
+ const [isSavingWebsite, setIsSavingWebsite] = useState(false);
return (
- <form
- ref={formRef}
- onSubmit={handleSubmit((data) => executeAsync(data))}
- className="flex w-full flex-col gap-4 text-left"
- >
- <label>
- <span className="text-sm font-medium text-neutral-800">Website</span>
- <div className="relative">
- <input
- type="url"
- className={cn(
- "mt-2 block w-full rounded-md focus:outline-none sm:text-sm",
- errors.website
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="https://example.com"
- {...register("website")}
- />
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<Globe className="size-4" />}
- onClick={() => alert("WIP")}
- />
- </div>
- <p className="mt-1.5 text-xs text-neutral-500">
- Verification may take up to 48 hours.
- </p>
- </label>
-
- <label>
- <span className="text-sm font-medium text-neutral-800">Instagram</span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- instagram.com/
- </span>
+ <>
+ <DomainVerificationModal
+ showDomainVerificationModal={domainVerificationData !== null}
+ setShowDomainVerificationModal={() => setDomainVerificationData(null)}
+ domain={domainVerificationData?.domain || ""}
+ txtRecord={domainVerificationData?.txtRecord || ""}
+ />
+ <form
+ onSubmit={handleSubmit(async (data) => {
+ const result = await executeAsync(data);
+
+ if (result?.data?.success)
+ router.push(country === "US" ? "/onboarding/verify" : "/programs");
+ })}
+ className="flex w-full flex-col gap-4 text-left"
+ >
+ <label>
+ <span className="text-sm font-medium text-neutral-800">Website</span>
+ <div className="relative">
<input
- type="text"
+ type="url"
className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.instagram
+ "mt-2 block w-full rounded-md focus:outline-none sm:text-sm",
+ errors.website
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
: "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
)}
- placeholder="handle"
- {...register("instagram")}
+ placeholder="https://example.com"
+ {...register("website")}
+ />
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<Globe className="size-4" />}
+ loading={isSavingWebsite}
+ disabled={!website || getFieldState("website").invalid}
+ onClick={async () => {
+ setIsSavingWebsite(true);
+ try {
+ const result = await updateOnlinePresenceAction({
+ website: getValues("website"),
+ });
+ console.log(result);
+
+ try {
+ if (
+ !result?.data?.website ||
+ !result?.data?.websiteTxtRecord
+ ) {
+ throw new Error(
+ "Missing website or TXT record in update result",
+ );
+ }
+
+ setDomainVerificationData({
+ domain: new URL(result.data.website).hostname,
+ txtRecord: result.data.websiteTxtRecord,
+ });
+ } catch (e) {
+ toast.error("Failed to start website verification");
+ console.error("Failed to start website verification", e);
+ }
+ } finally {
+ setIsSavingWebsite(false);
+ }
+ }}
/>
</div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<Instagram className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
-
- <label>
- <span className="text-sm font-medium text-neutral-800">TikTok</span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- tiktok.com/@
- </span>
- <input
- type="text"
- className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.tiktok
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="handle"
- {...register("tiktok")}
+ <p className="mt-1.5 text-xs text-neutral-500">
+ Verification may take up to 48 hours.
+ </p>
+ </label>
+
+ <label>
+ <span className="text-sm font-medium text-neutral-800">
+ Instagram
+ </span>
+ <div className="relative">
+ <div className="mt-2 flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ instagram.com/
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.instagram
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("instagram")}
+ />
+ </div>
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<Instagram className="size-3.5" />}
+ onClick={() => alert("WIP")}
/>
</div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<TikTok className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
-
- <label>
- <span className="text-sm font-medium text-neutral-800">YouTube</span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- youtube.com/@
- </span>
- <input
- type="text"
- className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.youtube
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="handle"
- {...register("youtube")}
+ </label>
+
+ <label>
+ <span className="text-sm font-medium text-neutral-800">TikTok</span>
+ <div className="relative">
+ <div className="mt-2 flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ tiktok.com/@
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.tiktok
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("tiktok")}
+ />
+ </div>
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<TikTok className="size-3.5" />}
+ onClick={() => alert("WIP")}
/>
</div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<YouTube className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
-
- <label>
- <span className="text-sm font-medium text-neutral-800">X/Twitter</span>
- <div className="relative">
- <div className="mt-2 flex rounded-md">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
- x.com/
- </span>
- <input
- type="text"
- className={cn(
- "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
- errors.twitter
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
- )}
- placeholder="handle"
- {...register("twitter")}
+ </label>
+
+ <label>
+ <span className="text-sm font-medium text-neutral-800">YouTube</span>
+ <div className="relative">
+ <div className="mt-2 flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ youtube.com/@
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.youtube
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("youtube")}
+ />
+ </div>
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<YouTube className="size-3.5" />}
+ onClick={() => alert("WIP")}
/>
</div>
- <Button
- className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
- variant="secondary"
- text="Verify"
- icon={<Twitter className="size-3.5" />}
- onClick={() => alert("WIP")}
- />
- </div>
- </label>
-
- <Button
- type="submit"
- text="Continue"
- className="mt-2"
- loading={isSubmitting || isSubmitSuccessful}
- />
- </form>
+ </label>
+
+ <label>
+ <span className="text-sm font-medium text-neutral-800">
+ X/Twitter
+ </span>
+ <div className="relative">
+ <div className="mt-2 flex rounded-md">
+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-3 text-neutral-500 sm:text-sm">
+ x.com/
+ </span>
+ <input
+ type="text"
+ className={cn(
+ "block w-full rounded-none rounded-r-md focus:outline-none sm:text-sm",
+ errors.twitter
+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",
+ )}
+ placeholder="handle"
+ {...register("twitter")}
+ />
+ </div>
+ <Button
+ className="absolute right-1.5 top-1/2 h-7 w-fit -translate-y-1/2 px-2.5"
+ variant="secondary"
+ text="Verify"
+ icon={<Twitter className="size-3.5" />}
+ onClick={() => alert("WIP")}
+ />
+ </div>
+ </label>
+
+ <Button
+ type="submit"
+ text="Continue"
+ className="mt-2"
+ loading={isSubmitting || isSubmitSuccessful}
+ />
+ </form>
+ </>
);
}
diff --git a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx
index e5d1d973ed..90a3e4ac79 100644
--- a/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx
+++ b/apps/web/app/partners.dub.co/(onboarding)/onboarding/online-presence/page.tsx
@@ -12,7 +12,7 @@ export default function OnlinePresencePage() {
Your online presence
</h1>
- <p className="mt-2 text-sm text-neutral-600">
+ <p className="animate-slide-up-fade mt-2 text-sm text-neutral-600 [animation-delay:500ms] [animation-duration:1s] [animation-fill-mode:both]">
These improve your reputation score and rank you higher. Verification
is optional and can be done later.
</p>
diff --git a/apps/web/lib/actions/partners/update-online-presence.ts b/apps/web/lib/actions/partners/update-online-presence.ts
index 7bf32be6ef..287a8290f9 100644
--- a/apps/web/lib/actions/partners/update-online-presence.ts
+++ b/apps/web/lib/actions/partners/update-online-presence.ts
@@ -1,6 +1,7 @@
"use server";
import { prisma } from "@dub/prisma";
+import { v4 as uuid } from "uuid";
import { z } from "zod";
import { authUserActionClient } from "../safe-action";
@@ -12,6 +13,12 @@ const updateOnlinePresenceSchema = z.object({
twitter: z.string().optional(),
});
+const updateOnlinePresenceResponseSchema = updateOnlinePresenceSchema.merge(
+ z.object({
+ websiteTxtRecord: z.string().nullable(),
+ }),
+);
+
export const updateOnlinePresenceAction = authUserActionClient
.schema(updateOnlinePresenceSchema)
.action(async ({ ctx, parsedInput }) => {
@@ -31,11 +38,32 @@ export const updateOnlinePresenceAction = authUserActionClient
throw new Error("Partner not found");
}
+ let domainChanged = false;
+
+ try {
+ let oldDomain = partner.website
+ ? new URL(partner.website).hostname
+ : null;
+ let newDomain = parsedInput.website
+ ? new URL(parsedInput.website).hostname
+ : null;
+ domainChanged = oldDomain !== newDomain;
+ } catch (e) {
+ console.error(
+ "Failed to get domain from partner website",
+ { old: partner.website, new: parsedInput.website },
+ e,
+ );
+ domainChanged = true;
+ }
+
const updateData = {
...(parsedInput.website !== undefined && {
website: parsedInput.website,
- websiteVerifiedAt:
- parsedInput.website !== partner.website ? null : undefined,
+ ...(domainChanged && {
+ websiteVerifiedAt: null,
+ websiteTxtRecord: `dub-domain-verification=${uuid()}`,
+ }),
}),
...(parsedInput.instagram !== undefined && {
instagram: parsedInput.instagram,
@@ -59,10 +87,15 @@ export const updateOnlinePresenceAction = authUserActionClient
}),
};
- await prisma.partner.update({
+ const updatedPartner = await prisma.partner.update({
where: {
id: partner.id,
},
data: updateData,
});
+
+ return {
+ success: true,
+ ...updateOnlinePresenceResponseSchema.parse(updatedPartner),
+ };
});
diff --git a/apps/web/ui/modals/domain-verification-modal.tsx b/apps/web/ui/modals/domain-verification-modal.tsx
new file mode 100644
index 0000000000..24ec2853c2
--- /dev/null
+++ b/apps/web/ui/modals/domain-verification-modal.tsx
@@ -0,0 +1,105 @@
+import { Button, Modal } from "@dub/ui";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+
+interface DomainVerificationModalProps {
+ showDomainVerificationModal: boolean;
+ setShowDomainVerificationModal: Dispatch<SetStateAction<boolean>>;
+ domain: string;
+ txtRecord: string;
+}
+
+export function DomainVerificationModal(props: DomainVerificationModalProps) {
+ return (
+ <Modal
+ showModal={props.showDomainVerificationModal}
+ setShowModal={props.setShowDomainVerificationModal}
+ >
+ <DomainVerificationModalInner {...props} />
+ </Modal>
+ );
+}
+
+function DomainVerificationModalInner({
+ setShowDomainVerificationModal,
+ domain,
+ txtRecord,
+}: DomainVerificationModalProps) {
+ return (
+ <>
+ <div className="space-y-2 border-b border-neutral-200 p-4 sm:p-6">
+ <h3 className="text-lg font-medium leading-none">Verify your domain</h3>
+ </div>
+
+ <div className="bg-neutral-50 p-4 sm:p-6">
+ <p className="text-sm text-neutral-800">
+ To verify your domain {domain}, set the following TXT record on your
+ DNS provider:
+ </p>
+
+ <div className="mt-4 flex flex-col gap-2 rounded-lg border border-neutral-200 bg-white p-3">
+ <div className="flex items-center justify-between space-x-3 border-b border-neutral-200 pb-2">
+ <div className="text-sm text-neutral-500">Type</div>
+ <div className="font-mono text-sm">TXT</div>
+ </div>
+ <div className="flex items-center justify-between space-x-3 border-b border-neutral-200 pb-2">
+ <div className="text-sm text-neutral-500">Name</div>
+ <div className="font-mono text-sm">@</div>
+ </div>
+ <div className="flex items-center justify-between space-x-3">
+ <div className="text-sm text-neutral-500">Value</div>
+ <div className="font-mono text-sm">{txtRecord}</div>
+ </div>
+ </div>
+ </div>
+
+ <div className="flex items-center justify-end gap-2 border-t border-neutral-200 bg-neutral-50 px-4 py-5 sm:px-6">
+ <Button
+ onClick={() => setShowDomainVerificationModal(false)}
+ text="Close"
+ className="h-8 w-fit px-3"
+ />
+ </div>
+ </>
+ );
+}
+
+export function useDomainVerificationModal({
+ domain,
+ txtRecord,
+}: {
+ domain: string;
+ txtRecord: string;
+}) {
+ const [showDomainVerificationModal, setShowDomainVerificationModal] =
+ useState(false);
+
+ const DomainVerificationModalCallback = useCallback(() => {
+ return (
+ <DomainVerificationModal
+ showDomainVerificationModal={showDomainVerificationModal}
+ setShowDomainVerificationModal={setShowDomainVerificationModal}
+ domain={domain}
+ txtRecord={txtRecord}
+ />
+ );
+ }, [
+ showDomainVerificationModal,
+ setShowDomainVerificationModal,
+ domain,
+ txtRecord,
+ ]);
+
+ return useMemo(
+ () => ({
+ setShowDomainVerificationModal,
+ DomainVerificationModal: DomainVerificationModalCallback,
+ }),
+ [setShowDomainVerificationModal, DomainVerificationModalCallback],
+ );
+}