The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
search by stripe ID
Steven Tey1604c5ec517a
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsxindex 44a74b3f19..8275d9d586 100644--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/impersonate-user.tsx@@ -105,9 +105,16 @@ const Form = () => {if (text.toLowerCase().startsWith("mailto:")) {text = text.slice(7);}+ const stripeCustomerId = text.match(/cus_[a-zA-Z0-9]+/)?.[0];+ if (+ stripeCustomerId &&+ (text.startsWith("cus_") || text.includes("stripe.com"))+ ) {+ text = stripeCustomerId;+ }e.currentTarget.value = text;}}- placeholder="[email protected], acme, or acme.com"+ placeholder="[email protected], acme, acme.com, or cus_"aria-invalid="true"/>{pending && (diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsxindex 60593dac26..5cb4f96b7d 100644--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx@@ -11,8 +11,9 @@ export default function AdminPage() {<div className="flex flex-col space-y-4 px-5 py-10"><h2 className="text-xl font-semibold">Impersonate User</h2><p className="text-sm text-neutral-500">- Get a login link by user/partner email, workspace slug, or domain.- Workspace and domain lookups impersonate the main owner.+ Get a login link by user/partner email, workspace slug, domain, or+ Stripe customer ID. Workspace, domain, and Stripe lookups impersonate+ the main owner.</p><ImpersonateUser /></div>diff --git a/apps/web/app/(ee)/api/admin/impersonate/route.ts b/apps/web/app/(ee)/api/admin/impersonate/route.tsindex 28a1ca2655..a4dcf37a4d 100644--- a/apps/web/app/(ee)/api/admin/impersonate/route.ts+++ b/apps/web/app/(ee)/api/admin/impersonate/route.ts@@ -103,13 +103,18 @@ const ownerSelect = {type ImpersonateIdentifier =| { type: "email"; email: string }| { type: "slug"; slug: string }- | { type: "domain"; domain: string };+ | { type: "domain"; domain: string }+ | { type: "stripeCustomerId"; stripeCustomerId: string };++const STRIPE_CUSTOMER_ID_REGEX = /cus_[a-zA-Z0-9]+/;function parseImpersonateQuery(raw: unknown,): ImpersonateIdentifier | { error: string } {if (typeof raw !== "string" || !raw.trim()) {- return { error: "Enter a user email, workspace slug, or domain" };+ return {+ error: "Enter a user email, workspace slug, domain, or Stripe customer ID",+ };}let query = raw.trim();@@ -125,6 +130,14 @@ function parseImpersonateQuery(return { type: "email", email: parsed.data };}+ const stripeCustomerId = query.match(STRIPE_CUSTOMER_ID_REGEX)?.[0];+ if (+ stripeCustomerId &&+ (query.startsWith("cus_") || query.includes("stripe.com"))+ ) {+ return { type: "stripeCustomerId", stripeCustomerId };+ }+let hostname: string | undefined;let pathname: string | undefined;try {@@ -158,13 +171,17 @@ function parseImpersonateQuery(return { type: "slug", slug };}- return { error: "Enter a user email, workspace slug, or domain" };+ return {+ error: "Enter a user email, workspace slug, domain, or Stripe customer ID",+ };}// POST /api/admin/impersonateexport const POST = withAdmin(async ({ req }) => {- const { query, email, slug, domain } = await req.json();- const parsed = parseImpersonateQuery(query ?? email ?? slug ?? domain);+ const { query, email, slug, domain, stripeCustomerId } = await req.json();+ const parsed = parseImpersonateQuery(+ query ?? email ?? slug ?? domain ?? stripeCustomerId,+ );if ("error" in parsed) {return new Response(parsed.error, { status: 400 });@@ -388,6 +405,45 @@ async function findUser(identifier: ImpersonateIdentifier) {return { user };}+ if (identifier.type === "stripeCustomerId") {+ const project = await prisma.project.findUnique({+ where: {+ stripeId: identifier.stripeCustomerId,+ },+ select: ownerSelect,+ });++ if (project) {+ const user = project.users[0]?.user;+ if (!user?.email) {+ return { error: "Workspace owner not found" };+ }+ return { user };+ }++ const customer = await prisma.customer.findUnique({+ where: {+ stripeCustomerId: identifier.stripeCustomerId,+ },+ select: {+ project: {+ select: ownerSelect,+ },+ },+ });++ if (!customer?.project) {+ return { error: "Workspace not found for this Stripe customer ID" };+ }++ const user = customer.project.users[0]?.user;+ if (!user?.email) {+ return { error: "Workspace owner not found" };+ }++ return { user };+ }+const project = await prisma.project.findUnique({where: {slug: identifier.slug,