The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fixed team switcher
Steven Tey063571568ab0
diff --git a/components/layout/app/list-box.tsx b/components/layout/app/list-box.tsxindex 5f05121b4d..7bc75a7cb5 100644--- a/components/layout/app/list-box.tsx+++ b/components/layout/app/list-box.tsx@@ -6,22 +6,26 @@ import BlurImage from "@/components/shared/blur-image";import useSWR from "swr";import { fetcher } from "@/lib/utils";import { ProjectProps } from "@/lib/api/types";+import { useSession } from "next-auth/react";export default function ListBox() {const { data: projects } = useSWR<ProjectProps[]>("/api/projects", fetcher);const router = useRouter();++ const { data: session } = useSession();+const selected = useMemo(() => {- const { teamSlug } = router.query;+ const { slug } = router.query;return (- projects?.find(({ slug }) => slug === teamSlug) || {- name: "Dub.sh",- slug: "dub",+ projects?.find((project) => project.slug === slug) || {+ name: session?.user?.name || session?.user?.email || "User",+ slug: "/",});- }, [router, projects]);+ }, [router, projects, session]);- if (!projects)+ if (!projects || !router.isReady)return (<div className="w-52 h-9 px-2 rounded-lg bg-gray-100 animate-pulse flex justify-end items-center"><ChevronUpDown className="h-4 w-4 text-gray-400" aria-hidden="true" />@@ -40,7 +44,12 @@ export default function ListBox() {<Listbox.Button className="relative w-full rounded-lg bg-white hover:bg-gray-100 py-1.5 pl-3 pr-10 text-left focus:outline-none text-sm active:scale-95 transition-all duration-75"><div className="flex justify-start items-center space-x-3"><BlurImage- src={`https://avatar.tobi.sh/${selected.slug}`}+ src={+ selected.slug === "/"+ ? session?.user?.image ||+ `https://avatars.dicebear.com/api/micah/${session?.user?.email}.svg`+ : `https://avatar.tobi.sh/${selected.slug}`+ }alt={selected.name}className="w-8 h-8 flex-shrink-0 rounded-full overflow-hidden border border-gray-300"width={48}diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 978a03f817..6c09ee9663 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -1,7 +1,8 @@import { NextApiRequest, NextApiResponse } from "next";import { redis } from "@/lib/redis";import { getSession } from "@/lib/api/auth";-import { customAlphabet } from "nanoid";++// This is a special route for creating custom dub.sh links.export default async function handler(req: NextApiRequest,@@ -22,20 +23,16 @@ export default async function handler(// POST /api/links – create a new link} else if (req.method === "POST") {- let { hostname, key, url } = req.body;- if (!hostname || !key || !url) {- return res.status(400).json({ error: "Missing hostname, key or url" });+ let { key, url } = req.body;+ if (!key || !url) {+ return res.status(400).json({ error: "Missing key or url" });}- const pipeline = redis.pipeline();- pipeline.hsetnx(`${hostname}:links`, key, url);- pipeline.zadd(`dub.sh:timestamps:${session?.user.id}`, {- score: Date.now(),- member: key,- });-- const response = await pipeline.exec();-- if (response === [1, 1]) {+ const response = await redis.hsetnx(`dub.sh:links`, key, url);+ if (response === 1) {+ await redis.zadd(`dub.sh:timestamps:${session?.user.id}`, {+ score: Date.now(),+ member: key,+ });return res.status(200).json({key,url,