The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add settings, rename referrals_embed cookie, SHOW_EMBEEDED_REFERRALS false for now
Steven Tey4cd4047427d8
diff --git a/apps/web/app/app.dub.co/embed/referrals/payouts.tsx b/apps/web/app/app.dub.co/embed/referrals/payouts.tsxindex 1f6684681d..533c83a102 100644--- a/apps/web/app/app.dub.co/embed/referrals/payouts.tsx+++ b/apps/web/app/app.dub.co/embed/referrals/payouts.tsx@@ -1,5 +1,5 @@import { PayoutStatus } from "@dub/prisma/client";-import { InfoTooltip } from "@dub/ui";+import { Button, InfoTooltip } from "@dub/ui";import { currencyFormatter } from "@dub/utils";export function ReferralsEmbedPayouts({@@ -9,9 +9,18 @@ export function ReferralsEmbedPayouts({}) {return (<div className="flex flex-col justify-between gap-4 rounded-lg border border-neutral-200 bg-white p-4">- <div className="flex items-center gap-1">- <p className="text-sm text-neutral-500">Payouts</p>- <InfoTooltip content="Payouts are processed at the start of each month. Your earnings are automatically transferred to your bank account." />+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-1">+ <p className="text-sm text-neutral-500">Payouts</p>+ <InfoTooltip content="Payouts are processed at the start of each month. Your earnings are automatically transferred to your bank account." />+ </div>+ <a href="https://partners.dub.co/register" target="_blank">+ <Button+ text="Settings"+ variant="secondary"+ className="h-7 p-2 text-sm"+ />+ </a></div><div className="grid gap-1">{[diff --git a/apps/web/lib/embed/constants.ts b/apps/web/lib/embed/constants.tsindex ee6da11c20..9d2afc93db 100644--- a/apps/web/lib/embed/constants.ts+++ b/apps/web/lib/embed/constants.ts@@ -2,4 +2,14 @@export const EMBED_PUBLIC_TOKEN_PREFIX = "dub_embed_";export const EMBED_PUBLIC_TOKEN_LENGTH = 36;export const EMBED_PUBLIC_TOKEN_EXPIRY = 24 * 60 * 60; // 24 hours-export const EMBED_PUBLIC_TOKEN_COOKIE_NAME = "embed_public_token";++// Referrals embed token+export const REFERRALS_EMBED_PUBLIC_TOKEN_COOKIE_NAME =+ "dub_referrals_embed_token";++// Analytics embed token+export const ANALYTICS_EMBED_PUBLIC_TOKEN_COOKIE_NAME =+ "dub_analytics_embed_token";++// TODO REMOVE ONCE WE LAUNCH TO GA+export const SHOW_EMBEEDED_REFERRALS = false;diff --git a/apps/web/lib/embed/referrals/auth.ts b/apps/web/lib/embed/referrals/auth.tsindex ee47fe5da0..ad53a4d074 100644--- a/apps/web/lib/embed/referrals/auth.ts+++ b/apps/web/lib/embed/referrals/auth.ts@@ -5,7 +5,7 @@ import { Link, Program } from "@dub/prisma/client";import { getSearchParams } from "@dub/utils";import { AxiomRequest, withAxiom } from "next-axiom";import { cookies } from "next/headers";-import { EMBED_PUBLIC_TOKEN_COOKIE_NAME } from "../constants";+import { REFERRALS_EMBED_PUBLIC_TOKEN_COOKIE_NAME } from "../constants";import { referralsEmbedToken } from "./token-class";interface WithReferralsEmbedTokenHandler {@@ -46,7 +46,7 @@ export const withReferralsEmbedToken = (const cookieStore = cookies();const tokenFromCookie = cookieStore.get(- EMBED_PUBLIC_TOKEN_COOKIE_NAME,+ REFERRALS_EMBED_PUBLIC_TOKEN_COOKIE_NAME,)?.value;if (!tokenFromCookie) {diff --git a/apps/web/lib/middleware/embed.ts b/apps/web/lib/middleware/embed.tsindex c2ab0ed01c..1199e0b5b7 100644--- a/apps/web/lib/middleware/embed.ts+++ b/apps/web/lib/middleware/embed.ts@@ -1,5 +1,5 @@import { NextRequest, NextResponse } from "next/server";-import { EMBED_PUBLIC_TOKEN_COOKIE_NAME } from "../embed/constants";+import { REFERRALS_EMBED_PUBLIC_TOKEN_COOKIE_NAME } from "../embed/constants";import { referralsEmbedToken } from "../embed/referrals/token-class";import { parse } from "./utils";@@ -18,7 +18,7 @@ export default async function EmbedMiddleware(req: NextRequest) {if (tokenData) {return NextResponse.rewrite(new URL(`/app.dub.co${fullPath}`, req.url), {headers: {- "Set-Cookie": `${EMBED_PUBLIC_TOKEN_COOKIE_NAME}=${token}; HttpOnly; Secure; SameSite=None; Path=/`,+ "Set-Cookie": `${REFERRALS_EMBED_PUBLIC_TOKEN_COOKIE_NAME}=${token}; HttpOnly; Secure; SameSite=None; Path=/`,},});}diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsxindex be3f0543e3..237233b988 100644--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx@@ -1,5 +1,6 @@"use client";+import { SHOW_EMBEEDED_REFERRALS } from "@/lib/embed/constants";import usePrograms from "@/lib/swr/use-programs";import { useRouterStuff } from "@dub/ui";import {@@ -216,11 +217,15 @@ const NAV_AREAS: SidebarNavAreas<{icon: ShieldCheck,href: "/account/settings/security",},- {- name: "Referrals",- icon: Gift,- href: "/account/settings/referrals",- },+ ...(SHOW_EMBEEDED_REFERRALS+ ? [+ {+ name: "Referrals",+ icon: Gift,+ href: "/account/settings/referrals",+ },+ ]+ : []),],},],diff --git a/apps/web/ui/layout/sidebar/refer-button.tsx b/apps/web/ui/layout/sidebar/refer-button.tsxindex 61c1cff260..65178e15d0 100644--- a/apps/web/ui/layout/sidebar/refer-button.tsx+++ b/apps/web/ui/layout/sidebar/refer-button.tsx@@ -1,5 +1,6 @@"use client";+import { SHOW_EMBEEDED_REFERRALS } from "@/lib/embed/constants";import { Gift } from "@dub/ui/icons";import Link from "next/link";import { usePathname } from "next/navigation";@@ -7,7 +8,7 @@ import { usePathname } from "next/navigation";export function ReferButton() {const pathname = usePathname();- if (pathname === "/account/settings/referrals") {+ if (pathname === "/account/settings/referrals" && !SHOW_EMBEEDED_REFERRALS) {return null;}diff --git a/apps/web/ui/layout/sidebar/user-dropdown.tsx b/apps/web/ui/layout/sidebar/user-dropdown.tsxindex 8ee4fb88c4..dc0906460a 100644--- a/apps/web/ui/layout/sidebar/user-dropdown.tsx+++ b/apps/web/ui/layout/sidebar/user-dropdown.tsx@@ -1,5 +1,6 @@"use client";+import { SHOW_EMBEEDED_REFERRALS } from "@/lib/embed/constants";import { Avatar, Gift, Icon, Popover, User } from "@dub/ui";import { cn } from "@dub/utils";import { LogOut } from "lucide-react";@@ -37,13 +38,15 @@ export default function UserDropdown() {href="/account/settings"onClick={() => setOpenPopover(false)}/>- <UserOption- as={Link}- label="Refer and earn"- icon={Gift}- href="/account/settings/referrals"- onClick={() => setOpenPopover(false)}- />+ {SHOW_EMBEEDED_REFERRALS && (+ <UserOption+ as={Link}+ label="Refer and earn"+ icon={Gift}+ href="/account/settings/referrals"+ onClick={() => setOpenPopover(false)}+ />+ )}<UserOptionas="button"type="button"