The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Added SSO/SAML waitlist
Steven Tey38ce090b2515
diff --git a/app/ui/tooltip.tsx b/app/ui/tooltip.tsxindex 21c9aaaa09..6b323d6528 100644--- a/app/ui/tooltip.tsx+++ b/app/ui/tooltip.tsx@@ -8,6 +8,8 @@ import { ReactNode, useRef, useState } from "react";import * as TooltipPrimitive from "@radix-ui/react-tooltip";import { AnimatePresence, motion, useAnimation } from "framer-motion";import BlurImage from "#/ui/blur-image";+import Button from "./button";+import Script from "next/script";export default function Tooltip({children,@@ -175,3 +177,33 @@ export function OGImageProxy() {</div>);}++export function SSOWaitlist() {+ const [opening, setOpening] = useState(false);+ return (+ <>+ <Script src="https://tally.so/widgets/embed.js" strategy="lazyOnload" />++ <div className="flex max-w-sm flex-col items-center space-y-3 p-5 text-center">+ <h3 className="font-semibold text-gray-800">SAML/SSO</h3>+ <p className="text-sm text-gray-600">+ SAML/SSO is coming soon. Interested in early access? Join the+ waitlist.+ </p>++ <Button+ text="Join waitlist"+ loading={opening}+ onClick={() => {+ setOpening(true);+ // @ts-ignore+ window.Tally?.openPopup("waexqB", {+ width: 540,+ onOpen: () => setOpening(false),+ });+ }}+ />+ </div>+ </>+ );+}diff --git a/components/app/modals/delete-account-modal.tsx b/components/app/modals/delete-account-modal.tsxnew file mode 100644index 0000000000..82ede51196--- /dev/null+++ b/components/app/modals/delete-account-modal.tsx@@ -0,0 +1,142 @@+import { useRouter } from "next/router";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";+import { toast } from "sonner";+import BlurImage from "#/ui/blur-image";+import Modal from "@/components/shared/modal";+import Button from "#/ui/button";+import { useSession } from "next-auth/react";++function DeleteAccountModal({+ showDeleteAccountModal,+ setShowDeleteAccountModal,+}: {+ showDeleteAccountModal: boolean;+ setShowDeleteAccountModal: Dispatch<SetStateAction<boolean>>;+}) {+ const router = useRouter();+ const { data: session, update } = useSession();+ const [deleting, setDeleting] = useState(false);++ async function deleteAccount() {+ setDeleting(true);+ await fetch(`/api/user`, {+ method: "DELETE",+ headers: {+ "Content-Type": "application/json",+ },+ }).then(async (res) => {+ if (res.status === 200) {+ update();+ // delay to allow for the route change to complete+ await new Promise((resolve) =>+ setTimeout(() => {+ router.push("/register");+ resolve(null);+ }, 200),+ );+ } else {+ setDeleting(false);+ const error = await res.text();+ throw error;+ }+ });+ }++ return (+ <Modal+ showModal={showDeleteAccountModal}+ setShowModal={setShowDeleteAccountModal}+ >+ <div className="inline-block w-full transform overflow-hidden bg-white align-middle shadow-xl transition-all sm:max-w-md sm:rounded-2xl sm:border sm:border-gray-200">+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">+ <BlurImage+ src={+ session?.user?.image ||+ `https://avatars.dicebear.com/api/micah/${session?.user?.email}.svg`+ }+ alt={+ session?.user?.name || session?.user?.email || "Delete Account"+ }+ className="h-10 w-10 rounded-full border border-gray-200"+ width={20}+ height={20}+ />+ <h3 className="text-lg font-medium">Delete Account</h3>+ <p className="text-center text-sm text-gray-500">+ Warning: This will permanently delete your account and all your+ Dub.sh links and their respective stats.+ </p>+ </div>++ <form+ onSubmit={async (e) => {+ e.preventDefault();+ toast.promise(deleteAccount(), {+ loading: "Deleting account...",+ success: "Account deleted successfully!",+ error: (err) => err,+ });+ }}+ className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16"+ >+ <div>+ <label+ htmlFor="verification"+ className="block text-sm text-gray-700"+ >+ To verify, type{" "}+ <span className="font-semibold text-black">+ confirm delete account+ </span>{" "}+ below+ </label>+ <div className="relative mt-1 rounded-md shadow-sm">+ <input+ type="text"+ name="verification"+ id="verification"+ pattern="confirm delete account"+ required+ autoFocus={false}+ className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ />+ </div>+ </div>++ <Button+ text="Confirm delete account"+ variant="danger"+ loading={deleting}+ />+ </form>+ </div>+ </Modal>+ );+}++export function useDeleteAccountModal() {+ const [showDeleteAccountModal, setShowDeleteAccountModal] = useState(false);++ const DeleteAccountModalCallback = useCallback(() => {+ return (+ <DeleteAccountModal+ showDeleteAccountModal={showDeleteAccountModal}+ setShowDeleteAccountModal={setShowDeleteAccountModal}+ />+ );+ }, [showDeleteAccountModal, setShowDeleteAccountModal]);++ return useMemo(+ () => ({+ setShowDeleteAccountModal,+ DeleteAccountModal: DeleteAccountModalCallback,+ }),+ [setShowDeleteAccountModal, DeleteAccountModalCallback],+ );+}diff --git a/components/app/modals/delete-project-modal.tsx b/components/app/modals/delete-project-modal.tsxindex c59be723f0..f3fdc48538 100644--- a/components/app/modals/delete-project-modal.tsx+++ b/components/app/modals/delete-project-modal.tsx@@ -12,6 +12,7 @@ import BlurImage from "#/ui/blur-image";import { LoadingDots } from "#/ui/icons";import Modal from "@/components/shared/modal";import useProject from "@/lib/swr/use-project";+import Button from "#/ui/button";function DeleteProjectModal({showDeleteProjectModal,@@ -123,20 +124,11 @@ function DeleteProjectModal({</div></div>- <button- disabled={deleting}- className={`${- deleting- ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"- : "border-red-600 bg-red-600 text-white hover:bg-white hover:text-red-600"- } flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none`}- >- {deleting ? (- <LoadingDots color="#808080" />- ) : (- <p>Confirm delete project</p>- )}- </button>+ <Button+ text="Confirm delete project"+ variant="danger"+ loading={deleting}+ /></form></div></Modal>diff --git a/lib/api/links.ts b/lib/api/links.tsindex fe78595649..3885ccc0ca 100644--- a/lib/api/links.ts+++ b/lib/api/links.ts@@ -366,3 +366,38 @@ export async function archiveLink(},});}++/* Delete all dub.sh links associated with a user when it's deleted */+export async function deleteUserLinks(userId: string) {+ const links = await prisma.link.findMany({+ where: {+ userId,+ domain: "dub.sh",+ },+ select: {+ key: true,+ proxy: true,+ },+ });+ const pipeline = redis.pipeline();+ links.forEach(({ key }) => {+ pipeline.del(`dub.sh:${key}`);+ });+ return await Promise.allSettled([+ pipeline.exec(), // delete all links from redis+ // remove all images from cloudinary+ ...links.map(({ key, proxy }) =>+ proxy+ ? cloudinary.v2.uploader.destroy(`dub.sh/${key}`, {+ invalidate: true,+ })+ : Promise.resolve(),+ ),+ prisma.link.deleteMany({+ where: {+ userId,+ domain: "dub.sh",+ },+ }),+ ]);+}diff --git a/package.json b/package.jsonindex 782b4d446e..da71c5de0f 100644--- a/package.json+++ b/package.json@@ -76,7 +76,7 @@"rehype-slug": "^5.1.0","remark-gfm": "^3.0.1","shiki": "^0.14.1",- "sonner": "^0.3.5",+ "sonner": "^0.4.0","stripe": "^11.1.0","swr": "^2.1.5","tailwind-scrollbar-hide": "^1.1.7",diff --git a/pages/api/user/index.ts b/pages/api/user/index.tsindex c385d60116..1ae562fa3f 100644--- a/pages/api/user/index.ts+++ b/pages/api/user/index.ts@@ -1,3 +1,4 @@+import { deleteUserLinks } from "@/lib/api/links";import { withUserAuth } from "@/lib/auth";import prisma from "@/lib/prisma";@@ -22,8 +23,35 @@ export default withUserAuth(async (req, res, session) => {return res.status(422).end("Email is already in use.");}}+ // DELETE /api/user – delete a specific user+ } else if (req.method === "DELETE") {+ const userIsOwnerOfProjects = await prisma.projectUsers.findMany({+ where: {+ userId: session.user.id,+ role: "owner",+ },+ });+ if (userIsOwnerOfProjects.length > 0) {+ return res+ .status(422)+ .end(+ "You must transfer ownership of your projects or delete them before you can delete your account.",+ );+ } else {+ const deleteLinks = await deleteUserLinks(session.user.id);+ const response = await prisma.user.delete({+ where: {+ id: session.user.id,+ },+ });+ console.log({+ deleteLinks: JSON.stringify(deleteLinks),+ response,+ });+ return res.status(200).json({ deleteLinks, response });+ }} else {- res.setHeader("Allow", ["PUT"]);+ res.setHeader("Allow", ["PUT", "DELETE"]);return res.status(405).json({ error: `Method ${req.method} Not Allowed` });}});diff --git a/pages/app/login.tsx b/pages/app/login.tsxindex eb5d69ae12..9f17e93d43 100644--- a/pages/app/login.tsx+++ b/pages/app/login.tsx@@ -7,6 +7,7 @@ import Background from "@/components/shared/background";import { toast } from "sonner";import Button from "#/ui/button";import { Google } from "@/components/shared/icons";+import { SSOWaitlist } from "#/ui/tooltip";export default function Login() {const [showEmailOption, setShowEmailOption] = useState(false);@@ -120,7 +121,7 @@ export default function Login() {<Buttontext="Continue with SAML SSO"disabled- disabledTooltip="SAML/SSO is coming soon"+ disabledTooltip={<SSOWaitlist />}/>{noSuchAccount && (diff --git a/pages/app/register.tsx b/pages/app/register.tsxindex 6f2df82d8c..bbae6c0353 100644--- a/pages/app/register.tsx+++ b/pages/app/register.tsx@@ -5,6 +5,7 @@ import BlurImage from "#/ui/blur-image";import Background from "@/components/shared/background";import { Google } from "@/components/shared/icons";import Button from "#/ui/button";+import { SSOWaitlist, TooltipContent } from "#/ui/tooltip";export default function Register() {const [clickedGoogle, setClickedGoogle] = useState(false);@@ -41,7 +42,7 @@ export default function Register() {<Buttontext="Continue with SAML SSO"disabled- disabledTooltip="SAML/SSO is coming soon"+ disabledTooltip={<SSOWaitlist />}/></div></div>diff --git a/pages/app/settings.tsx b/pages/app/settings.tsxindex cfd8fff62b..91fde415dc 100644--- a/pages/app/settings.tsx+++ b/pages/app/settings.tsx@@ -1,10 +1,16 @@+import Button from "#/ui/button";import Form from "#/ui/form";+import { useDeleteAccountModal } from "@/components/app/modals/delete-account-modal";import SettingsLayout from "@/components/layout/app/settings-layout";import { useSession } from "next-auth/react";import { toast } from "sonner";export default function PersonalSettings() {const { data: session, update } = useSession();++ const { setShowDeleteAccountModal, DeleteAccountModal } =+ useDeleteAccountModal();+return (<SettingsLayout><Form@@ -62,6 +68,29 @@ export default function PersonalSettings() {})}/>++ <div className="rounded-lg border border-red-600 bg-white">+ <DeleteAccountModal />+ <div className="flex flex-col space-y-3 p-5 sm:p-10">+ <h2 className="text-xl font-medium">Delete Account</h2>+ <p className="text-sm text-gray-500">+ Permanently delete your Dub account and all of your Dub.sh links ++ their stats. This action cannot be undone - please proceed with+ caution.+ </p>+ </div>+ <div className="border-b border-red-600" />++ <div className="flex items-center justify-end p-3 sm:px-10">+ <div className="w-32">+ <Button+ text="Delete Account"+ variant="danger"+ onClick={() => setShowDeleteAccountModal(true)}+ />+ </div>+ </div>+ </div></SettingsLayout>);}diff --git a/yarn.lock b/yarn.lockindex 6a12e288f1..38d02394a6 100644--- a/yarn.lock+++ b/yarn.lock@@ -8439,10 +8439,10 @@ socks@^2.3.3, socks@^2.6.2:ip "^2.0.0"smart-buffer "^4.2.0"-sonner@^0.3.5:- version "0.3.5"- resolved "https://registry.yarnpkg.com/sonner/-/sonner-0.3.5.tgz#5ef175732cb7b637c6460620ab01a0fba0e6a36b"- integrity sha512-yIwaQ4dftMvFApuruto2t7wGyyaPRpj5qYBWYJIz4Z7uGcVn0IfqI/hWN0JyJN4izNbZFuCYZISf3fOGnvSlNQ==+sonner@^0.4.0:+ version "0.4.0"+ resolved "https://registry.yarnpkg.com/sonner/-/sonner-0.4.0.tgz#65c4930a31f5fc3a98fe1ace1971050726bc155d"+ integrity sha512-zEU/Mzur39xYPpyQOOCmN6YQftl5v+TSmdsmWEbWf6ovnOvnHyRwR7+/6BIBbzwRa8+3v06FJlpF7J3KS4Ll9Q==sort-keys@^5.0.0:version "5.0.0"