The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
LinkedIn profile verification (#3611)
Kiran K8b46ecde37da
diff --git a/apps/web/.env.example b/apps/web/.env.exampleindex e8637eea91..3fae905b48 100644--- a/apps/web/.env.example+++ b/apps/web/.env.example@@ -162,8 +162,6 @@ TWITTER_CLIENT_ID=TWITTER_CLIENT_SECRET=TIKTOK_CLIENT_ID=TIKTOK_CLIENT_SECRET=-LINKEDIN_CLIENT_ID=-LINKEDIN_CLIENT_SECRET=YOUTUBE_API_KEY=# Scrape Creatorsdiff --git a/apps/web/lib/actions/partners/start-partner-platform-verification.ts b/apps/web/lib/actions/partners/start-partner-platform-verification.tsindex c167742ae2..6c8c177c3f 100644--- a/apps/web/lib/actions/partners/start-partner-platform-verification.ts+++ b/apps/web/lib/actions/partners/start-partner-platform-verification.ts@@ -49,8 +49,8 @@ type VerificationParams = {/*** Starts the social platform verification process for a partner.* Supports three verification methods:- * - OAuth: For platforms like Twitter, TikTok, and LinkedIn (returns OAuth URL)- * - Verification Code: For platforms like YouTube and Instagram (returns code to display)+ * - OAuth: For platforms like Twitter and TikTok (returns OAuth URL)+ * - Verification Code: For platforms like YouTube, Instagram, and LinkedIn (returns code to display)* - TXT Record: For website verification (returns DNS TXT record)*/export const startPartnerPlatformVerificationAction = authPartnerActionClientdiff --git a/apps/web/lib/actions/partners/verify-social-account-by-code.ts b/apps/web/lib/actions/partners/verify-social-account-by-code.tsindex fc130f2958..389039df45 100644--- a/apps/web/lib/actions/partners/verify-social-account-by-code.ts+++ b/apps/web/lib/actions/partners/verify-social-account-by-code.ts@@ -1,5 +1,6 @@"use server";+import { getLinkedInPost } from "@/lib/api/scrape-creators/get-linkedin-post";import { getSocialProfile } from "@/lib/api/scrape-creators/get-social-profile";import { ratelimit } from "@/lib/upstash";import { redis } from "@/lib/upstash/redis";@@ -11,6 +12,7 @@ import { authPartnerActionClient } from "../safe-action";const schema = z.object({platform: z.enum(PlatformType),handle: z.string().min(1),+ postUrl: z.url().optional(),});// Verify social accounts using the verification code@@ -18,10 +20,14 @@ export const verifySocialAccountByCodeAction = authPartnerActionClient.inputSchema(schema).action(async ({ ctx, parsedInput }) => {const { partner } = ctx;- const { platform, handle } = parsedInput;+ const { platform, handle, postUrl } = parsedInput;- if (!["youtube", "instagram"].includes(platform)) {- throw new Error("Only YouTube and Instagram are supported.");+ if (!["youtube", "instagram", "linkedin"].includes(platform)) {+ throw new Error("Only YouTube, Instagram, and LinkedIn are supported.");+ }++ if (platform === "linkedin" && !postUrl) {+ throw new Error("Please provide the LinkedIn post URL.");}// Rate limit check@@ -71,9 +77,53 @@ export const verifySocialAccountByCodeAction = authPartnerActionClientreturn;}- // Verifies that a verification code exists in the account's profile bio/description.- // Fetches the account profile and checks if the provided code appears in any of the- // profile text fields (description, about, bio, summary).+ if (platform === "linkedin") {+ // For LinkedIn, fetch the post and check for the verification code+ const linkedInPost = await getLinkedInPost(postUrl!);++ if (!linkedInPost.description || linkedInPost.description.length === 0) {+ throw new Error(+ "We could not find any text content in the LinkedIn post. Please ensure it is visible and try again.",+ );+ }++ if (!linkedInPost.description.includes(verificationCode)) {+ throw new Error(+ "The verification code was not found in the LinkedIn post. Please add the code exactly as provided and try again.",+ );+ }++ // Verify the post author matches the stored handle+ const authorUrl = linkedInPost.author.url?.toLowerCase() ?? "";+ const authorSlug = authorUrl.match(/\/in\/([^/?]+)/)?.[1];++ if (+ !authorSlug ||+ authorSlug !== partnerPlatform.identifier.toLowerCase()+ ) {+ throw new Error(+ "The LinkedIn post does not appear to belong to the account you are verifying. Please ensure you are sharing a post from the correct account.",+ );+ }++ await prisma.partnerPlatform.update({+ where: {+ partnerId_type: {+ partnerId: partner.id,+ type: platform,+ },+ },+ data: {+ verifiedAt: new Date(),+ subscribers: BigInt(linkedInPost.author.followers),+ },+ });++ await redis.del(cacheKey);+ return;+ }++ // For YouTube and Instagram, verify code in profile descriptionconst socialProfile = await getSocialProfile({platform,handle,diff --git a/apps/web/lib/api/partner-profile/partner-platforms-providers.ts b/apps/web/lib/api/partner-profile/partner-platforms-providers.tsindex c68983fb67..7846934173 100644--- a/apps/web/lib/api/partner-profile/partner-platforms-providers.ts+++ b/apps/web/lib/api/partner-profile/partner-platforms-providers.ts@@ -118,44 +118,4 @@ export const PARTNER_PLATFORMS_PROVIDERS: Record<};},},-- // We don't support LinkedIn verification yet- linkedin: {- authUrl: "https://www.linkedin.com/oauth/v2/authorization",- tokenUrl: "https://www.linkedin.com/oauth/v2/accessToken",- clientId: process.env.LINKEDIN_CLIENT_ID ?? null,- clientSecret: process.env.LINKEDIN_CLIENT_SECRET ?? null,- scopes: "openid profile",- verify: async ({ handle, accessToken }) => {- if (!handle) {- return {- verified: false,- };- }-- // Fetch user info using OpenID Connect userinfo endpoint- const response = await fetch("https://api.linkedin.com/v2/userinfo", {- headers: {- Authorization: `Bearer ${accessToken}`,- },- });-- const userResponse = await response.json();-- if (!response.ok) {- console.error("Failed to verify LinkedIn handle", userResponse);-- return {- verified: false,- };- }-- // TODO:- // We can't verify the handle because the LinkedIn API doesn't return the vanity name in the response-- return {- verified: false,- };- },- },};diff --git a/apps/web/lib/api/scrape-creators/get-linkedin-post.ts b/apps/web/lib/api/scrape-creators/get-linkedin-post.tsnew file mode 100644index 0000000000..1ea8e9fb73--- /dev/null+++ b/apps/web/lib/api/scrape-creators/get-linkedin-post.ts@@ -0,0 +1,47 @@+import { scrapeCreatorsFetch } from "./client";++interface LinkedInPostResult {+ description: string | null;+ author: {+ url: string | null;+ followers: number;+ };+}++export async function getLinkedInPost(+ url: string,+): Promise<LinkedInPostResult> {+ const { data, error } = await scrapeCreatorsFetch(+ "/:version/:platform/:contentType",+ {+ params: {+ version: "v1",+ platform: "linkedin",+ contentType: "post",+ },+ query: {+ url,+ },+ },+ );++ if (error) {+ throw new Error(+ "We were unable to retrieve the LinkedIn post. Please check the URL and try again.",+ );+ }++ if (data.platform !== "linkedin") {+ throw new Error(+ "The provided URL does not appear to be a valid LinkedIn post.",+ );+ }++ return {+ description: data.description ?? data.headline ?? null,+ author: {+ url: data.author.url ?? null,+ followers: data.author.followers ?? 0,+ },+ };+}diff --git a/apps/web/lib/api/scrape-creators/get-social-content.ts b/apps/web/lib/api/scrape-creators/get-social-content.tsindex c557f2f4a6..b9ad2ae293 100644--- a/apps/web/lib/api/scrape-creators/get-social-content.ts+++ b/apps/web/lib/api/scrape-creators/get-social-content.ts@@ -15,13 +15,14 @@ interface GetSocialContentStatsParams {}const PLATFORM_CONTENT_TYPE: Record<- Exclude<PlatformType, "website" | "linkedin">,+ Exclude<PlatformType, "website">,"post" | "video" | "tweet"> = {youtube: "video",instagram: "post",twitter: "tweet",tiktok: "video",+ linkedin: "post",};const EMPTY_SOCIAL_CONTENT: SocialContent = {@@ -180,6 +181,24 @@ export async function getSocialContent({break;}+ case "linkedin": {+ const handleMatch = data.author?.url?.match(+ /linkedin\.com\/in\/([^\/\?]+)/i,+ );++ result = {+ publishedAt: data.datePublished ? new Date(data.datePublished) : null,+ handle: handleMatch?.[1] ?? null,+ platformId: null,+ views: 0,+ likes: data.likeCount,+ title: data.name ?? null,+ description: data.description ?? data.headline ?? null,+ thumbnailUrl: null,+ };+ break;+ }+default:result = {publishedAt: null,diff --git a/apps/web/lib/api/scrape-creators/schema.ts b/apps/web/lib/api/scrape-creators/schema.tsindex 355d8f107f..df835ac71e 100644--- a/apps/web/lib/api/scrape-creators/schema.ts+++ b/apps/web/lib/api/scrape-creators/schema.ts@@ -190,6 +190,14 @@ export const socialContentSchema = z.preprocess(platform: "tiktok",};}++ // LinkedIn detection+ if ("author" in data && "likeCount" in data && "commentCount" in data) {+ return {+ ...data,+ platform: "linkedin",+ };+ }}return data;@@ -311,5 +319,24 @@ export const socialContentSchema = z.preprocess(}).optional(),}),++ z.object({+ platform: z.literal("linkedin"),+ name: z.string().nullish(),+ description: z.string().nullish(),+ headline: z.string().nullish(),+ datePublished: z.string().nullish(),+ likeCount: z+ .number()+ .nullish()+ .transform((val) => val ?? 0),+ author: z.object({+ url: z.string(),+ followers: z+ .number()+ .nullish()+ .transform((val) => val ?? 0),+ }),+ }),]),);diff --git a/apps/web/lib/bounty/social-content.ts b/apps/web/lib/bounty/social-content.tsindex 347e31e2b7..79dd53911d 100644--- a/apps/web/lib/bounty/social-content.ts+++ b/apps/web/lib/bounty/social-content.ts@@ -29,6 +29,13 @@ export const BOUNTY_SOCIAL_PLATFORMS = [metrics: ["likes", "views"],placeholder: "https://x.com/username/status/",},+ {+ value: "linkedin",+ label: "LinkedIn",+ postType: "post",+ metrics: ["likes"],+ placeholder: "https://www.linkedin.com/posts/",+ },] as const;export const BOUNTY_SOCIAL_PLATFORM_VALUES = BOUNTY_SOCIAL_PLATFORMS.map(@@ -60,4 +67,6 @@ export const SOCIAL_URL_HOST_TO_PLATFORM: Record<string, PlatformType> = {"m.instagram.com": "instagram","twitter.com": "twitter","x.com": "twitter",+ "linkedin.com": "linkedin",+ "www.linkedin.com": "linkedin",};diff --git a/apps/web/tests/partners/create-partner.test.ts b/apps/web/tests/partners/create-partner.test.tsindex 228c693da3..c1e5fc40fa 100644--- a/apps/web/tests/partners/create-partner.test.ts+++ b/apps/web/tests/partners/create-partner.test.ts@@ -4,15 +4,15 @@ import { Link, Partner } from "@dub/prisma/client";import { R2_URL } from "@dub/utils";import slugify from "@sindresorhus/slugify";import { describe, expect, test } from "vitest";--function reEscape(s: string) {- return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");-}import { randomId, randomPartnerEmail } from "../utils/helpers";import { IntegrationHarness } from "../utils/integration";import { E2E_PARTNER_GROUP, E2E_PROGRAM } from "../utils/resource";import { normalizedPartnerDateFields } from "./resource";+function reEscape(s: string) {+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");+}+const EnrolledPartnerSchema = EnrolledPartnerSchemaDate.extend(normalizedPartnerDateFields.shape,);@@ -98,9 +98,7 @@ describe.sequential("POST /partners", async () => {const parsed = EnrolledPartnerSchema.parse(data);expect(parsed.name).toBe(partner.name);expect(parsed.email).toBe(partner.email);- const keyRe = new RegExp(- `^${reEscape(username)}(-[a-z0-9]{4})?$`,- );+ const keyRe = new RegExp(`^${reEscape(username)}(-[a-z0-9]{4})?$`);expect(parsed.links).toEqual(expect.arrayContaining([expect.objectContaining({diff --git a/apps/web/ui/modals/social-verification-by-code-modal.tsx b/apps/web/ui/modals/social-verification-by-code-modal.tsxindex 0ef89e012b..de33131e69 100644--- a/apps/web/ui/modals/social-verification-by-code-modal.tsx+++ b/apps/web/ui/modals/social-verification-by-code-modal.tsx@@ -5,7 +5,7 @@ import { Button, buttonVariants, CopyButton, Modal } from "@dub/ui";import { cn } from "@dub/utils";import { X } from "lucide-react";import { useAction } from "next-safe-action/hooks";-import { Dispatch, ReactNode, SetStateAction } from "react";+import { Dispatch, ReactNode, SetStateAction, useState } from "react";import { toast } from "sonner";interface SocialVerificationByCodeModalProps {@@ -20,15 +20,25 @@ interface PlatformInfo {name: string;title: string;instruction: string;- getProfileUrl: (handle: string) => string;+ openLabel: string;+ verifyTitle: string;+ verifyDescription: string;+ getProfileUrl: (handle: string, verificationCode: string) => string;}-const PLATFORM_INFO: Record<"youtube" | "instagram", PlatformInfo> = {+const PLATFORM_INFO: Record<+ "youtube" | "instagram" | "linkedin",+ PlatformInfo+> = {youtube: {name: "YouTube",title: "Edit your YouTube channel",instruction:"Navigate to your channel settings and add the 6 digit code above to your channel description temporarily.",+ openLabel: "Open channel",+ verifyTitle: "Verify account",+ verifyDescription:+ "Click verify below once you've added the code to your channel description.",getProfileUrl: (handle) => `https://www.youtube.com/@${handle}/about`,},instagram: {@@ -36,8 +46,26 @@ const PLATFORM_INFO: Record<"youtube" | "instagram", PlatformInfo> = {title: "Edit your Instagram profile",instruction:"Navigate to your profile settings and add the 6 digit code above to your bio temporarily.",+ openLabel: "Open profile",+ verifyTitle: "Verify account",+ verifyDescription:+ "Click verify below once you've added the code to your bio.",getProfileUrl: (handle) => `https://www.instagram.com/${handle}/`,},+ linkedin: {+ name: "LinkedIn",+ title: "Create a LinkedIn post",+ instruction:+ "Click the button below to create a LinkedIn post with the code pre-filled. You can remove the post after verification.",+ openLabel: "Create post on LinkedIn",+ verifyTitle: "Paste post URL and verify account",+ verifyDescription:+ "After creating the post, paste the post URL below and click verify.",+ getProfileUrl: (_handle, code) =>+ `https://www.linkedin.com/feed/?shareActive=true&text=${encodeURIComponent(+ `I'm claiming my Dub profile on partners.dub.co 🤘\n\nEarn by partnering with world-class companies like Framer, Polymarket, Perplexity, and more.\n\nVerification: ${code}`,+ )}`,+ },};export function SocialVerificationByCodeModal(@@ -60,9 +88,10 @@ function SocialVerificationByCodeModalInner({verificationCode,}: SocialVerificationByCodeModalProps) {const { mutate: mutatePartner } = usePartnerProfile();+ const [postUrl, setPostUrl] = useState("");const platformInfo: PlatformInfo = PLATFORM_INFO[platform];- const profileUrl = platformInfo.getProfileUrl(handle);+ const isLinkedIn = platform === "linkedin";const { executeAsync, isPending } = useAction(verifySocialAccountByCodeAction,@@ -81,12 +110,24 @@ function SocialVerificationByCodeModalInner({);const handleVerify = async () => {+ if (isLinkedIn && !postUrl) {+ toast.error("Please enter the LinkedIn post URL.");+ return;+ }+await executeAsync({platform,handle,+ ...(isLinkedIn && { postUrl }),});};+ let stepNumber = 1;++ if (!platformInfo) {+ return null;+ }+return (<><div className="flex items-center justify-between border-b border-neutral-200 p-4 sm:px-6">@@ -104,7 +145,7 @@ function SocialVerificationByCodeModalInner({<div className="flex flex-col gap-4 bg-neutral-50 p-4 sm:p-6"><Step- stepNumber={1}+ stepNumber={stepNumber++}title="Copy the code below"description="You'll use this to verify ownership of your account.">@@ -117,12 +158,12 @@ function SocialVerificationByCodeModalInner({</Step><Step- stepNumber={2}+ stepNumber={stepNumber++}title={platformInfo.title}description={platformInfo.instruction}><a- href={profileUrl}+ href={platformInfo.getProfileUrl(handle, verificationCode)}target="_blank"rel="noopener noreferrer"className={cn(@@ -130,19 +171,29 @@ function SocialVerificationByCodeModalInner({"flex h-8 w-full items-center justify-center rounded-md border px-3 text-sm",)}>- Open {platform === "youtube" ? "channel" : "profile"}+ {platformInfo.openLabel}</a></Step><Step- stepNumber={3}- title="Verify account"- description={`Click verify below once you've added the code to your ${platform === "youtube" ? "channel description" : "bio"}.`}+ stepNumber={stepNumber++}+ title={platformInfo.verifyTitle}+ description={platformInfo.verifyDescription}>+ {isLinkedIn && (+ <input+ type="url"+ value={postUrl}+ onChange={(e) => setPostUrl(e.target.value)}+ placeholder="https://www.linkedin.com/feed/update/urn:li:activity:..."+ className="block w-full rounded-md border border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ />+ )}<Buttontext="Verify account"className="h-8 w-full px-3"loading={isPending}+ disabled={isLinkedIn && !postUrl}onClick={handleVerify}/></Step>diff --git a/apps/web/ui/partners/bounties/bounty-platform-icons.ts b/apps/web/ui/partners/bounties/bounty-platform-icons.tsindex f165b9dc56..53c328680b 100644--- a/apps/web/ui/partners/bounties/bounty-platform-icons.ts+++ b/apps/web/ui/partners/bounties/bounty-platform-icons.ts@@ -1,5 +1,5 @@import { BountySocialPlatform } from "@/lib/types";-import { Instagram, TikTok, Twitter, YouTube } from "@dub/ui";+import { Instagram, LinkedIn, TikTok, Twitter, YouTube } from "@dub/ui";import { ComponentType } from "react";export const PLATFORM_ICONS: Record<@@ -10,4 +10,5 @@ export const PLATFORM_ICONS: Record<tiktok: TikTok,instagram: Instagram,twitter: Twitter,+ linkedin: LinkedIn,};diff --git a/apps/web/ui/partners/bounties/bounty-social-content-preview.tsx b/apps/web/ui/partners/bounties/bounty-social-content-preview.tsxindex c4af7c0757..476831b356 100644--- a/apps/web/ui/partners/bounties/bounty-social-content-preview.tsx+++ b/apps/web/ui/partners/bounties/bounty-social-content-preview.tsx@@ -8,7 +8,6 @@ import {} from "@/lib/types";import { cn } from "@dub/utils";import { useState } from "react";-import { PLATFORM_ICONS } from "./bounty-platform-icons";interface BountySocialContentPreviewProps {bounty: Pick<PartnerBountyProps, "id" | "submissionRequirements">;@@ -98,6 +97,21 @@ function getSocialContentEmbedUrl({}}+ if (platform === "linkedin") {+ if (host === "linkedin.com") {+ // LinkedIn post URLs:+ // /posts/username_activity-{id}-xxxx+ // /feed/update/urn:li:activity:{id}+ const activityMatch = parsed.pathname.match(/activity[_-](\d+)/);+ const urnMatch = parsed.pathname.match(/activity[:%]3A(\d+)/);+ const activityId = activityMatch?.[1] ?? urnMatch?.[1];++ return activityId+ ? `https://www.linkedin.com/embed/feed/update/urn:li:activity:${activityId}`+ : null;+ }+ }+return null;} catch {return null;@@ -128,6 +142,10 @@ function getSocialContentEmbedAspectRatio({return "aspect-square";}+ if (platform === "linkedin") {+ return "aspect-video";+ }+return "aspect-video";} catch {return "aspect-video";@@ -163,26 +181,8 @@ export function BountySocialContentPreview({url,});- const PlatformIcon = PLATFORM_ICONS[platform.value];-return (<div className="flex flex-col gap-2 rounded-xl border border-neutral-200 bg-white p-2">- {/* Channel row */}- {/* <div className="flex items-center gap-2 px-2 py-1">- <div className="flex size-6 shrink-0 items-center justify-center rounded-full bg-neutral-100">- <PlatformIcon className="size-3.5" />- </div>- <div className="min-w-0 flex-1" />- <a- href={url}- target="_blank"- rel="noopener noreferrer"- className="flex h-7 shrink-0 items-center rounded-lg border border-neutral-200 bg-white px-2.5 text-sm font-medium text-neutral-900"- >- View- </a>- </div> */}-{/* Native embed */}<divclassName={cn(diff --git a/apps/web/ui/partners/partner-platforms-form.tsx b/apps/web/ui/partners/partner-platforms-form.tsxindex 3d91c8a9c4..0621f53183 100644--- a/apps/web/ui/partners/partner-platforms-form.tsx+++ b/apps/web/ui/partners/partner-platforms-form.tsx@@ -490,7 +490,6 @@ export const PartnerPlatformsForm = forwardRef<prefix="in/"icon={LinkedIn}disabled={disabled}- verifyDisabledTooltip="LinkedIn verification is coming soon."onVerifyClick={async () => {const handle = getValues("linkedin");@@ -655,7 +654,6 @@ function FormRow({}: {label: string;input: ReactNode;-property: keyof PartnerPlatformsFormData;prefix?: string;icon: Icon;@@ -740,6 +738,21 @@ function FormRow({posts > 0 ? `${nFormatter(Number(posts))} tweets` : null,].filter(Boolean) as string[];}++ if (property === "linkedin") {+ const linkedinPlatform = getPlatformData(+ partnerWithPlatforms.platforms,+ "linkedin",+ );++ const subscribers = linkedinPlatform?.subscribers ?? 0;++ return [+ subscribers > 0+ ? `${nFormatter(Number(subscribers))} followers`+ : null,+ ].filter(Boolean) as string[];+ }}return null;}, [partner, property, isVerified]);