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.

Add admin UI and API to request partner identity verification

Kiran K07a296459d55
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx
index 77852848a9..93a125809f 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/network-partner-application-sheet.tsx
@@ -28,6 +28,7 @@ import { LayoutGroup, motion } from "motion/react";
import Link from "next/link";
import { useEffect, useId, useState } from "react";
import { NetworkPartnerChangeHistory } from "./network-partner-change-history";
+import { NetworkRequestIdentityVerification } from "./request-identity-verification";
type NetworkPartnerSheetTabId = "about" | "programs" | "duplicates";
@@ -307,6 +308,9 @@ export function NetworkPartnerApplicationSheet({
changeHistoryLog={partner.changeHistoryLog}
/>
</div>
+ <div className="@3xl/sheet:max-h-[50dvh] @3xl/sheet:overflow-y-auto @3xl/sheet:pr-1 overflow-x-hidden">
+ <NetworkRequestIdentityVerification partner={partner} />
+ </div>
</div>
<div className="@3xl/sheet:order-1">
<div className="border-border-subtle overflow-hidden rounded-xl border bg-neutral-100">
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/request-identity-verification.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/request-identity-verification.tsx
new file mode 100644
index 0000000000..7975d7d50f
--- /dev/null
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/network/request-identity-verification.tsx
@@ -0,0 +1,113 @@
+"use client";
+
+import { AdminNetworkPartner } from "@/lib/types";
+import { useConfirmModal } from "@/ui/modals/confirm-modal";
+import { Button, CopyButton } from "@dub/ui";
+import { ShieldCheck } from "@dub/ui/icons";
+import { useEffect, useState } from "react";
+import { toast } from "sonner";
+
+export function NetworkRequestIdentityVerification({
+ partner,
+}: {
+ partner: Pick<AdminNetworkPartner, "id">;
+}) {
+ const [sessionUrl, setSessionUrl] = useState<string | null>(null);
+ const [isLoading, setIsLoading] = useState(false);
+
+ useEffect(() => {
+ setSessionUrl(null);
+ }, [partner.id]);
+
+ const handleGenerateSession = async () => {
+ setIsLoading(true);
+
+ try {
+ const response = await fetch(
+ `/api/admin/partners/${partner.id}/identity-verification`,
+ {
+ method: "POST",
+ },
+ );
+
+ if (!response.ok) {
+ throw new Error(
+ (await response.text()) || "Failed to generate Veriff session.",
+ );
+ }
+
+ const { sessionUrl: url } = (await response.json()) as {
+ sessionUrl: string;
+ };
+
+ setSessionUrl(url);
+ toast.success("Veriff session generated.");
+ } catch (error) {
+ toast.error(
+ error instanceof Error
+ ? error.message
+ : "Failed to generate Veriff session.",
+ );
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ const { setShowConfirmModal, confirmModal } = useConfirmModal({
+ title: "Request identity verification",
+ description:
+ "This will trigger a new Veriff verification session for the partner.",
+ confirmText: "Generate session",
+ onConfirm: handleGenerateSession,
+ });
+
+ return (
+ <>
+ {confirmModal}
+ <section className="w-full min-w-0 max-w-full overflow-x-hidden rounded-xl border border-neutral-200 bg-neutral-100 p-4">
+ <div className="flex items-center gap-2">
+ <ShieldCheck className="size-4 text-neutral-500" />
+ <h3 className="text-sm font-semibold text-neutral-900">
+ Request identity verification
+ </h3>
+ </div>
+
+ <p className="mt-1 text-xs text-neutral-500">
+ This will trigger a new verification process for the partner.
+ </p>
+
+ <Button
+ variant="secondary"
+ text="Generate Veriff Session"
+ className="mt-2"
+ loading={isLoading}
+ onClick={() => setShowConfirmModal(true)}
+ />
+
+ {sessionUrl && (
+ <div className="mt-3 space-y-1">
+ <p className="text-xs font-medium text-neutral-700">
+ Verification URL
+ </p>
+ <div className="flex items-center gap-2 rounded-lg border border-neutral-200 bg-white px-3 py-2">
+ <a
+ href={sessionUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="min-w-0 flex-1 truncate text-xs text-blue-600 underline-offset-2 hover:underline"
+ >
+ {sessionUrl}
+ </a>
+ <CopyButton
+ value={sessionUrl}
+ variant="neutral"
+ className="shrink-0 p-1 [&>*]:h-3 [&>*]:w-3"
+ successMessage="Copied verification URL to clipboard!"
+ />
+ </div>
+ </div>
+ )}
+ </section>
+ </>
+ );
+}
diff --git a/apps/web/app/(ee)/api/admin/partners/[partnerId]/identity-verification/route.ts b/apps/web/app/(ee)/api/admin/partners/[partnerId]/identity-verification/route.ts
new file mode 100644
index 0000000000..1e74009a9b
--- /dev/null
+++ b/apps/web/app/(ee)/api/admin/partners/[partnerId]/identity-verification/route.ts
@@ -0,0 +1,87 @@
+import { withAdmin } from "@/lib/auth";
+import { createVeriffSession } from "@/lib/veriff/create-veriff-session";
+import {
+ mergeVeriffMetadata,
+ parseVeriffMetadata,
+} from "@/lib/veriff/veriff-metadata";
+import { prisma } from "@dub/prisma";
+import { addDays } from "date-fns";
+import { NextResponse } from "next/server";
+
+// POST /api/admin/partners/[partnerId]/identity-verification
+export const POST = withAdmin(
+ async ({ params }) => {
+ const { partnerId } = params;
+
+ const partner = await prisma.partner.findUnique({
+ where: {
+ id: partnerId,
+ },
+ select: {
+ id: true,
+ email: true,
+ name: true,
+ identityVerificationStatus: true,
+ veriffSessionId: true,
+ veriffMetadata: true,
+ },
+ });
+
+ if (!partner) {
+ return new Response("Partner not found.", { status: 404 });
+ }
+
+ if (partner.identityVerificationStatus) {
+ switch (partner.identityVerificationStatus) {
+ case "approved":
+ throw new Error(
+ "This partner's identity is already verified. No further action is required.",
+ );
+ case "submitted":
+ case "review":
+ throw new Error(
+ "A verification attempt is already in progress. Please wait for it to complete or resubmit.",
+ );
+ }
+ }
+
+ const veriffMetadata = parseVeriffMetadata(partner.veriffMetadata);
+
+ // If the session is already created and not expired, return the existing session
+ // this is to avoid creating duplicate sessions
+ if (
+ partner.veriffSessionId &&
+ veriffMetadata.sessionUrl &&
+ veriffMetadata.sessionExpiresAt &&
+ veriffMetadata.sessionExpiresAt > new Date()
+ ) {
+ return NextResponse.json({
+ sessionUrl: veriffMetadata.sessionUrl,
+ });
+ }
+
+ const { verification } = await createVeriffSession({
+ partner,
+ });
+
+ await prisma.partner.update({
+ where: {
+ id: partner.id,
+ },
+ data: {
+ veriffSessionId: verification.id,
+ veriffMetadata: mergeVeriffMetadata(partner.veriffMetadata, {
+ sessionUrl: verification.url,
+ sessionExpiresAt: addDays(new Date(), 7),
+ }),
+ },
+ });
+
+ return NextResponse.json({
+ sessionUrl: verification.url,
+ });
+ },
+ {
+ requiredRoles: ["owner"],
+ },
+);