The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix admin portal
Steven Tey1e2218417212
diff --git a/apps/web/app/app.dub.co/(onboarding)/background.tsx b/apps/web/app/app.dub.co/(onboarding)/background.tsxdeleted file mode 100644index 0339bd3036..0000000000--- a/apps/web/app/app.dub.co/(onboarding)/background.tsx+++ /dev/null@@ -1,69 +0,0 @@-"use client";--import { cn } from "@dub/utils";-import Image from "next/image";-import { usePathname } from "next/navigation";-import { useState } from "react";--export function Background(props: { showAnimation?: boolean }) {- const pathname = usePathname();- const [isGridLoaded, setIsGridLoaded] = useState(false);- const [isBackgroundLoaded, setIsBackgroundLoaded] = useState(false);- const isLoaded = isGridLoaded && isBackgroundLoaded;-- const showAnimation =- props.showAnimation || pathname === "/onboarding/welcome";-- return (- <div- className={cn(- "absolute inset-0 overflow-hidden bg-white transition-opacity duration-300",- showAnimation ? (isLoaded ? "opacity-100" : "opacity-0") : "opacity-40",- )}- >- <BackgroundGradient className="opacity-15" />- <div className="absolute left-1/2 top-0 -translate-x-1/2 opacity-50 transition-all sm:opacity-100">- <Image- src="https://assets.dub.co/misc/welcome-background-grid.svg"- onLoad={() => setIsGridLoaded(true)}- alt=""- width={1750}- height={1046}- className="absolute inset-0"- />- <Image- src="https://assets.dub.co/misc/welcome-background.svg"- onLoad={() => setIsBackgroundLoaded(true)}- alt=""- width={1750}- height={1046}- className={cn(- "relative min-w-[1000px] max-w-screen-2xl transition-opacity duration-300",- showAnimation ? "opacity-100" : "opacity-0",- )}- />- </div>- <BackgroundGradient className="opacity-100 mix-blend-soft-light" />- </div>- );-}--function BackgroundGradient({ className }: { className?: string }) {- return (- <div- className={cn(- "absolute left-0 top-0 aspect-square w-full overflow-hidden sm:aspect-[2/1]",- "[mask-image:radial-gradient(70%_100%_at_50%_0%,_black_70%,_transparent)]",- className,- )}- >- <div- className="absolute inset-0 saturate-150"- style={{- backgroundImage: `conic-gradient(from -45deg at 50% -10%, #3A8BFD 0deg, #FF0000 172.98deg, #855AFC 215.14deg, #FF7B00 257.32deg, #3A8BFD 360deg)`,- }}- />- <div className="absolute inset-0 backdrop-blur-[100px]" />- </div>- );-}diff --git a/apps/web/app/partners.dub.co/page.tsx b/apps/web/app/partners.dub.co/page.tsxnew file mode 100644index 0000000000..d244c917bd--- /dev/null+++ b/apps/web/app/partners.dub.co/page.tsx@@ -0,0 +1,38 @@+import { NewBackground } from "@/ui/shared/new-background";+import { Wordmark } from "@dub/ui";+import { constructMetadata } from "@dub/utils";++export const metadata = constructMetadata({+ noIndex: true,+});++export default function Partners() {+ return (+ <div>+ <NewBackground showAnimation />+ <div className="relative mx-auto mt-24 flex max-w-sm flex-col items-center px-3 text-center md:mt-32 md:px-8 lg:mt-48">+ <div className="animate-slide-up-fade relative flex w-auto items-center justify-center px-6 py-2 [--offset:20px] [animation-duration:1.3s] [animation-fill-mode:both]">+ <div className="absolute inset-0 opacity-10">+ {[...Array(3)].map((_, i) => (+ <div+ key={i}+ className="animate-pulse-scale absolute inset-0 rounded-full mix-blend-color-burn"+ style={{+ animationDelay: `${i * -2}s`,+ backgroundImage: `linear-gradient(90deg, #000, transparent, #000)`,+ }}+ />+ ))}+ </div>+ <Wordmark className="relative h-16" />+ </div>+ <h1 className="animate-slide-up-fade mt-10 text-2xl font-medium [--offset:10px] [animation-delay:250ms] [animation-duration:1s] [animation-fill-mode:both]">+ Dub Partner Portal+ </h1>+ <p className="animate-slide-up-fade mt-2 text-gray-500 [--offset:10px] [animation-delay:500ms] [animation-duration:1s] [animation-fill-mode:both]">+ Coming soon+ </p>+ </div>+ </div>+ );+}diff --git a/apps/web/lib/middleware/admin.ts b/apps/web/lib/middleware/admin.tsindex 1c8a461191..de4e78a45b 100644--- a/apps/web/lib/middleware/admin.ts+++ b/apps/web/lib/middleware/admin.ts@@ -1,41 +1,31 @@import { parse } from "@/lib/middleware/utils";import { DUB_WORKSPACE_ID } from "@dub/utils";-import { getToken } from "next-auth/jwt";import { NextRequest, NextResponse } from "next/server";import { prismaEdge } from "../prisma/edge";-import { UserProps } from "../types";+import { getUserViaToken } from "./utils/get-user-via-token";export default async function AdminMiddleware(req: NextRequest) {const { path } = parse(req);- const session = (await getToken({- req,- secret: process.env.NEXTAUTH_SECRET,- })) as {- id?: string;- email?: string;- user?: UserProps;- };+ const user = await getUserViaToken(req);- if (!session?.user?.id) {+ if (!user && path !== "/login") {return NextResponse.redirect(new URL("/login", req.url));- }-- const response = await prismaEdge.projectUsers.findUnique({- where: {- userId_projectId: {- userId: session.user.id,- projectId: DUB_WORKSPACE_ID,+ } else if (user) {+ const isAdminUser = await prismaEdge.projectUsers.findUnique({+ where: {+ userId_projectId: {+ userId: user.id,+ projectId: DUB_WORKSPACE_ID,+ },},- },- });-- if (!response) {- return NextResponse.redirect(new URL("/login", req.url));- }+ });- if (path === "/login") {- return NextResponse.redirect(new URL("/", req.url));+ if (!isAdminUser) {+ return NextResponse.next(); // throw 404 page+ } else if (path === "/login") {+ return NextResponse.redirect(new URL("/", req.url));+ }}return NextResponse.rewrite(diff --git a/apps/web/lib/middleware/partners.ts b/apps/web/lib/middleware/partners.tsnew file mode 100644index 0000000000..3eb681ae47--- /dev/null+++ b/apps/web/lib/middleware/partners.ts@@ -0,0 +1,10 @@+import { parse } from "@/lib/middleware/utils";+import { NextRequest, NextResponse } from "next/server";++export default function PartnersMiddleware(req: NextRequest) {+ const { path } = parse(req);++ return NextResponse.rewrite(+ new URL(`/partners.dub.co${path === "/" ? "" : path}`, req.url),+ );+}diff --git a/apps/web/middleware.ts b/apps/web/middleware.tsindex 1a43d3559a..5184862ec8 100644--- a/apps/web/middleware.ts+++ b/apps/web/middleware.ts@@ -14,7 +14,9 @@ import {DEFAULT_REDIRECTS,isValidUrl,} from "@dub/utils";+import { PARTNERS_HOSTNAMES } from "@dub/utils/src/constants";import { NextFetchEvent, NextRequest, NextResponse } from "next/server";+import PartnersMiddleware from "./lib/middleware/partners";export const config = {matcher: [@@ -59,6 +61,10 @@ export default async function middleware(req: NextRequest, ev: NextFetchEvent) {return AdminMiddleware(req);}+ if (PARTNERS_HOSTNAMES.has(domain)) {+ return PartnersMiddleware(req);+ }+if (isValidUrl(fullKey)) {return CreateLinkMiddleware(req);}diff --git a/packages/utils/src/constants/main.ts b/packages/utils/src/constants/main.tsindex 47ddd8117f..c0ca6b4a98 100644--- a/packages/utils/src/constants/main.ts+++ b/packages/utils/src/constants/main.ts@@ -45,6 +45,12 @@ export const ADMIN_HOSTNAMES = new Set(["admin.localhost:8888",]);+export const PARTNERS_HOSTNAMES = new Set([+ `partners.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,+ `partners-staging.${process.env.NEXT_PUBLIC_APP_DOMAIN}`,+ "partners.localhost:8888",+]);+export const DUB_LOGO = "https://assets.dub.co/logo.png";export const DUB_QR_LOGO = "https://assets.dub.co/logo.png";export const DUB_WORDMARK = "https://assets.dub.co/wordmark.png";