Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

New Feature: Dub API

Steven Teyf0a14f426090
diff --git a/app/inspect/[domain]/[key]/card.tsx b/app/inspect/[domain]/[key]/card.tsx
index f888980643..adc0acae68 100644
--- a/app/inspect/[domain]/[key]/card.tsx
+++ b/app/inspect/[domain]/[key]/card.tsx
@@ -38,7 +38,7 @@ export default function LinkInspectorCard({
>
{linkConstructor({ domain, key, pretty: true })}
</a>
- <CopyButton url={linkConstructor({ domain, key })} />
+ <CopyButton value={linkConstructor({ domain, key })} />
</div>
<a
href={url}
diff --git a/app/ui/avatar.tsx b/app/ui/avatar.tsx
index 622f496443..f16d7b027a 100644
--- a/app/ui/avatar.tsx
+++ b/app/ui/avatar.tsx
@@ -30,6 +30,18 @@ export default function Avatar({
`https://avatars.dicebear.com/api/micah/${user?.email}.svg`
}
className={cn("h-10 w-10 rounded-full border border-gray-300", className)}
+ draggable={false}
+ />
+ );
+}
+
+export function TokenAvatar({ id }: { id: string }) {
+ return (
+ <img
+ src={`https://api.dicebear.com/7.x/shapes/svg?seed=${id}`}
+ alt="avatar"
+ className="h-10 w-10 rounded-full"
+ draggable={false}
/>
);
}
diff --git a/app/ui/button.tsx b/app/ui/button.tsx
index 030ab84949..0d7e4b23b6 100644
--- a/app/ui/button.tsx
+++ b/app/ui/button.tsx
@@ -5,25 +5,22 @@ import Tooltip from "#/ui/tooltip";
import { cn } from "#/lib/utils";
import { ReactNode } from "react";
+interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
+ text: string;
+ variant?: "primary" | "secondary" | "success" | "danger";
+ loading?: boolean;
+ icon?: ReactNode;
+ disabledTooltip?: string | ReactNode;
+}
+
export default function Button({
text,
variant = "primary",
- className,
- onClick,
- disabled,
loading,
icon,
disabledTooltip,
-}: {
- text: string;
- variant?: "primary" | "secondary" | "success" | "danger";
- className?: string;
- onClick?: any;
- disabled?: boolean;
- loading?: boolean;
- icon?: ReactNode;
- disabledTooltip?: string | ReactNode;
-}) {
+ ...props
+}: ButtonProps) {
if (disabledTooltip) {
return (
<Tooltip content={disabledTooltip} fullWidth>
@@ -36,10 +33,10 @@ export default function Button({
return (
<button
// if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"
- type={onClick ? "button" : "submit"}
+ type={props.onClick ? "button" : "submit"}
className={cn(
"flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all focus:outline-none",
- disabled || loading
+ props.disabled || loading
? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"
: {
"border-black bg-black text-white hover:bg-white hover:text-black":
@@ -51,10 +48,10 @@ export default function Button({
"border-red-500 bg-red-500 text-white hover:bg-white hover:text-red-500":
variant === "danger",
},
- className,
+ props.className,
)}
- {...(onClick ? { onClick } : {})}
- disabled={disabled || loading}
+ disabled={props.disabled || loading}
+ {...props}
>
{loading ? <LoadingSpinner /> : icon ? icon : null}
<p>{text}</p>
diff --git a/app/ui/form.tsx b/app/ui/form.tsx
index 57d676a3bf..f82b896892 100644
--- a/app/ui/form.tsx
+++ b/app/ui/form.tsx
@@ -7,6 +7,7 @@ export default function Form({
description,
inputData,
helpText,
+ buttonText = "Save Changes",
disabledTooltip,
handleSubmit,
}: {
@@ -14,6 +15,7 @@ export default function Form({
description: string;
inputData: InputHTMLAttributes<HTMLInputElement>;
helpText?: string;
+ buttonText?: string;
disabledTooltip?: string | ReactNode;
handleSubmit: (data) => Promise<any>;
}) {
@@ -63,7 +65,7 @@ export default function Form({
<p className="text-sm text-gray-500">{helpText}</p>
<div>
<Button
- text="Save Changes"
+ text={buttonText}
loading={saving}
disabled={saveDisabled}
disabledTooltip={disabledTooltip}
diff --git a/app/ui/home/link-card.tsx b/app/ui/home/link-card.tsx
index df7bc0074f..b31b5ff4c4 100644
--- a/app/ui/home/link-card.tsx
+++ b/app/ui/home/link-card.tsx
@@ -163,7 +163,7 @@ export default function LinkCard({
>
{linkConstructor({ key, pretty: true })}
</a>
- <CopyButton url={linkConstructor({ key })} />
+ <CopyButton value={linkConstructor({ key })} />
<button
onClick={() => setShowLinkQRModal(true)}
className="group rounded-full bg-gray-100 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-100 focus:outline-none active:scale-95"
diff --git a/app/ui/number.tsx b/app/ui/number.tsx
index 0ef062f0c1..4fd0e0e48c 100644
--- a/app/ui/number.tsx
+++ b/app/ui/number.tsx
@@ -27,11 +27,7 @@ export default function Number({
</p>
{lastClicked && (
<p className="mt-1 text-xs text-gray-500">
- Last clicked {timeAgo(lastClicked)}{" "}
- {Date.now() - new Date(lastClicked).getTime() > 60000 &&
- Date.now() - new Date(lastClicked).getTime() < 82800000
- ? "ago"
- : ""}
+ Last clicked {timeAgo(lastClicked, { withAgo: true })}
</p>
)}
</div>
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index ff86c03abf..b32db55c13 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -271,7 +271,7 @@ export default function LinkCard({
})}
</a>
)}
- <CopyButton url={linkConstructor({ key, domain })} />
+ <CopyButton value={linkConstructor({ key, domain })} />
{comments && (
<Tooltip
content={
diff --git a/components/app/modals/delete-token-modal.tsx b/components/app/modals/delete-token-modal.tsx
new file mode 100644
index 0000000000..2c427ef735
--- /dev/null
+++ b/components/app/modals/delete-token-modal.tsx
@@ -0,0 +1,108 @@
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import { mutate } from "swr";
+import Modal from "#/ui/modal";
+import { toast } from "sonner";
+import Button from "#/ui/button";
+import { Token } from "@prisma/client";
+import { Logo } from "#/ui/icons";
+import { TokenAvatar } from "#/ui/avatar";
+import { timeAgo } from "#/lib/utils";
+import Badge from "#/ui/badge";
+
+function DeleteTokenModal({
+ showDeleteTokenModal,
+ setShowDeleteTokenModal,
+ token,
+}: {
+ showDeleteTokenModal: boolean;
+ setShowDeleteTokenModal: Dispatch<SetStateAction<boolean>>;
+ token: Token;
+}) {
+ const [removing, setRemoving] = useState(false);
+
+ return (
+ <Modal
+ showModal={showDeleteTokenModal}
+ setShowModal={setShowDeleteTokenModal}
+ >
+ <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">
+ <Logo />
+ <h3 className="text-lg font-medium">Delete API Key</h3>
+ <p className="text-center text-sm text-gray-500">
+ This will permanently delete the API key for and revoke all access to
+ your account. Are you sure you want to continue?
+ </p>
+ </div>
+
+ <div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16">
+ <div className="relative flex items-center space-x-3 rounded-md border border-gray-300 bg-white px-1 py-3">
+ <Badge
+ text={token.partialKey}
+ variant="neutral"
+ className="absolute right-2 top-2"
+ />
+ <TokenAvatar id={token.id} />
+ <div className="flex flex-col">
+ <h3 className="line-clamp-1 w-48 font-semibold text-gray-700">
+ {token.name}
+ </h3>
+ <p className="text-xs text-gray-500">
+ Last used {timeAgo(token.lastUsed, { withAgo: true })}
+ </p>
+ </div>
+ </div>
+ <Button
+ text="Confirm"
+ variant="danger"
+ autoFocus
+ loading={removing}
+ onClick={() => {
+ setRemoving(true);
+ fetch(`/api/user/tokens?id=${token.id}`, {
+ method: "DELETE",
+ headers: { "Content-Type": "application/json" },
+ }).then(async (res) => {
+ setRemoving(false);
+ if (res.status === 200) {
+ toast.success(`Successfully deleted API key`);
+ mutate("/api/user/tokens");
+ setShowDeleteTokenModal(false);
+ } else {
+ const error = await res.text();
+ toast.error(error);
+ }
+ });
+ }}
+ />
+ </div>
+ </Modal>
+ );
+}
+
+export function useDeleteTokenModal({ token }: { token: Token }) {
+ const [showDeleteTokenModal, setShowDeleteTokenModal] = useState(false);
+
+ const DeleteTokenModalCallback = useCallback(() => {
+ return (
+ <DeleteTokenModal
+ showDeleteTokenModal={showDeleteTokenModal}
+ setShowDeleteTokenModal={setShowDeleteTokenModal}
+ token={token}
+ />
+ );
+ }, [showDeleteTokenModal, setShowDeleteTokenModal]);
+
+ return useMemo(
+ () => ({
+ setShowDeleteTokenModal,
+ DeleteTokenModal: DeleteTokenModalCallback,
+ }),
+ [setShowDeleteTokenModal, DeleteTokenModalCallback],
+ );
+}
diff --git a/components/app/modals/token-created-modal.tsx b/components/app/modals/token-created-modal.tsx
new file mode 100644
index 0000000000..f6bdebb22c
--- /dev/null
+++ b/components/app/modals/token-created-modal.tsx
@@ -0,0 +1,71 @@
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import Modal from "#/ui/modal";
+import Button from "#/ui/button";
+import { Logo } from "#/ui/icons";
+import CopyButton from "@/components/shared/copy-button";
+
+function TokenCreatedModal({
+ showTokenCreatedModal,
+ setShowTokenCreatedModal,
+ token,
+}: {
+ showTokenCreatedModal: boolean;
+ setShowTokenCreatedModal: Dispatch<SetStateAction<boolean>>;
+ token: string;
+}) {
+ return (
+ <Modal
+ showModal={showTokenCreatedModal}
+ setShowModal={setShowTokenCreatedModal}
+ >
+ <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">
+ <Logo />
+ <h3 className="text-lg font-medium">API Key Created</h3>
+ <p className="text-center text-sm text-gray-500">
+ For security reasons, we will only show you the key once. Please copy
+ and store it somewhere safe.
+ </p>
+ </div>
+
+ <div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16">
+ <div className="flex items-center justify-between rounded-md border border-gray-300 bg-white p-3">
+ <p className="font-mono text-sm text-gray-500">{token}</p>
+ <CopyButton value={token} className="rounded-md" />
+ </div>
+ <Button
+ text="Done"
+ variant="secondary"
+ onClick={() => setShowTokenCreatedModal(false)}
+ />
+ </div>
+ </Modal>
+ );
+}
+
+export function useTokenCreatedModal({ token }: { token: string }) {
+ const [showTokenCreatedModal, setShowTokenCreatedModal] = useState(false);
+
+ const TokenCreatedModalCallback = useCallback(() => {
+ return (
+ <TokenCreatedModal
+ showTokenCreatedModal={showTokenCreatedModal}
+ setShowTokenCreatedModal={setShowTokenCreatedModal}
+ token={token}
+ />
+ );
+ }, [showTokenCreatedModal, setShowTokenCreatedModal]);
+
+ return useMemo(
+ () => ({
+ setShowTokenCreatedModal,
+ TokenCreatedModal: TokenCreatedModalCallback,
+ }),
+ [setShowTokenCreatedModal, TokenCreatedModalCallback],
+ );
+}
diff --git a/components/layout/app/nav-tabs.tsx b/components/layout/app/nav-tabs.tsx
index ee1ed83a23..0deb80f513 100644
--- a/components/layout/app/nav-tabs.tsx
+++ b/components/layout/app/nav-tabs.tsx
@@ -56,6 +56,8 @@ export default function NavTabs() {
return <div className="-mb-0.5 h-12 w-full" />;
}
+ console.log("HACKY", router.asPath.split("?")[0]);
+
if (!error) {
return (
<div className="-mb-0.5 flex h-12 items-center justify-start space-x-2 overflow-x-auto scrollbar-hide">
@@ -64,9 +66,12 @@ export default function NavTabs() {
key={href}
href={href}
className={`border-b-2 p-1 ${
- // hacky approach to getting the current tab – will replace with useSelectedLayoutSegments when upgrading to Next.js 13
- router.asPath.split("?")[0].split("/").slice(0, 3).join("/") ===
- href
+ // hacky approach to getting the current tab – will replace with useSelectedLayoutSegments when upgrading to Next.js App Router
+ router.asPath
+ .split("?")[0]
+ .split("/")
+ .slice(0, slug ? 3 : 2)
+ .join("/") === href
? "border-black text-black"
: "border-transparent text-gray-600 hover:text-black"
}`}
diff --git a/components/layout/app/settings-layout.tsx b/components/layout/app/settings-layout.tsx
index 3126aca000..6e194b68a8 100644
--- a/components/layout/app/settings-layout.tsx
+++ b/components/layout/app/settings-layout.tsx
@@ -34,7 +34,12 @@ export default function SettingsLayout({ children }: { children: ReactNode }) {
href: `/${slug}/settings/security`,
},
]
- : []),
+ : [
+ {
+ name: "API Keys",
+ href: "/settings/tokens",
+ },
+ ]),
];
return (
diff --git a/components/shared/copy-button.tsx b/components/shared/copy-button.tsx
index c8a812d86d..f0d90e3c52 100644
--- a/components/shared/copy-button.tsx
+++ b/components/shared/copy-button.tsx
@@ -3,20 +3,30 @@
import { useState } from "react";
import { Copy, Tick } from "@/components/shared/icons";
import { toast } from "sonner";
+import { cn } from "#/lib/utils";
-export default function CopyButton({ url }: { url: string }) {
+export default function CopyButton({
+ value,
+ className,
+}: {
+ value: string;
+ className?: string;
+}) {
const [copied, setCopied] = useState(false);
return (
<button
onClick={(e) => {
e.stopPropagation();
setCopied(true);
- navigator.clipboard.writeText(url).then(() => {
- toast.success("Copied shortlink to clipboard!");
+ navigator.clipboard.writeText(value).then(() => {
+ toast.success("Copied to clipboard!");
});
setTimeout(() => setCopied(false), 3000);
}}
- className="group rounded-full bg-gray-100 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-100 active:scale-95"
+ className={cn(
+ "group rounded-full bg-gray-100 p-1.5 transition-all duration-75 hover:scale-105 hover:bg-blue-100 active:scale-95",
+ className,
+ )}
>
<span className="sr-only">Copy</span>
{copied ? (
diff --git a/lib/utils.ts b/lib/utils.ts
index 0de345a021..984acf1180 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -156,10 +156,17 @@ export function linkConstructor({
return pretty ? link.replace(/^https?:\/\//, "") : link;
}
-export const timeAgo = (timestamp?: Date): string => {
- if (!timestamp) return "Just now";
+export const timeAgo = (
+ timestamp: Date | null,
+ {
+ withAgo,
+ }: {
+ withAgo?: boolean;
+ } = {},
+): string => {
+ if (!timestamp) return "Never";
const diff = Date.now() - new Date(timestamp).getTime();
- if (diff < 60000) {
+ if (diff < 1000) {
// less than 1 second
return "Just now";
} else if (diff > 82800000) {
@@ -173,7 +180,7 @@ export const timeAgo = (timestamp?: Date): string => {
: undefined,
});
}
- return ms(diff);
+ return `${ms(diff)}${withAgo ? " ago" : ""}`;
};
export const getDateTimeLocal = (timestamp?: Date): string => {
diff --git a/pages/api/user/tokens.ts b/pages/api/user/tokens.ts
new file mode 100644
index 0000000000..1f90966827
--- /dev/null
+++ b/pages/api/user/tokens.ts
@@ -0,0 +1,70 @@
+import { hashToken, withUserAuth } from "#/lib/auth";
+import prisma from "#/lib/prisma";
+import { customAlphabet } from "nanoid";
+
+const generateToken = customAlphabet(
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
+ 24,
+);
+
+export default withUserAuth(async (req, res, session) => {
+ // GET /api/user/tokens – get all tokens for a specific user
+ if (req.method === "GET") {
+ const tokens = await prisma.token.findMany({
+ where: {
+ userId: session.user.id,
+ },
+ select: {
+ id: true,
+ name: true,
+ partialKey: true,
+ createdAt: true,
+ lastUsed: true,
+ },
+ orderBy: [
+ {
+ lastUsed: "desc",
+ },
+ {
+ createdAt: "desc",
+ },
+ ],
+ });
+ return res.status(200).json(tokens);
+
+ // POST /api/user/tokens – create a new token for a specific user
+ } else if (req.method === "POST") {
+ const { name } = req.body;
+ const token = generateToken();
+ const hashedKey = hashToken(token);
+ // take first 3 and last 4 characters of the key
+ const partialKey = `${token.slice(0, 3)}...${token.slice(-4)}`;
+
+ await prisma.token.create({
+ data: {
+ name,
+ hashedKey,
+ partialKey,
+ userId: session.user.id,
+ },
+ });
+ return res.status(200).json({ token });
+
+ // DELETE /api/user/tokens – delete a token for a specific user
+ } else if (req.method === "DELETE") {
+ const { id } = req.query;
+ if (!id || typeof id !== "string") {
+ return res.status(400).end("Invalid token ID");
+ }
+ const response = await prisma.token.delete({
+ where: {
+ id,
+ userId: session.user.id,
+ },
+ });
+ return res.status(200).json(response);
+ } else {
+ res.setHeader("Allow", ["PUT", "DELETE"]);
+ return res.status(405).end(`Method ${req.method} Not Allowed`);
+ }
+});
diff --git a/pages/app/settings.tsx b/pages/app/settings/index.tsx
similarity index 100%
rename from pages/app/settings.tsx
rename to pages/app/settings/index.tsx
diff --git a/pages/app/settings/tokens.tsx b/pages/app/settings/tokens.tsx
new file mode 100644
index 0000000000..5d843c0815
--- /dev/null
+++ b/pages/app/settings/tokens.tsx
@@ -0,0 +1,157 @@
+import { fetcher, timeAgo } from "#/lib/utils";
+import { TokenAvatar } from "#/ui/avatar";
+import Form from "#/ui/form";
+import { LoadingSpinner } from "#/ui/icons";
+import Popover from "#/ui/popover";
+import { useDeleteTokenModal } from "@/components/app/modals/delete-token-modal";
+import { useTokenCreatedModal } from "@/components/app/modals/token-created-modal";
+import SettingsLayout from "@/components/layout/app/settings-layout";
+import IconMenu from "@/components/shared/icon-menu";
+import { Token } from "@prisma/client";
+import { FolderOpen, MoreVertical, Trash } from "lucide-react";
+import { useState } from "react";
+import { toast } from "sonner";
+import useSWR from "swr";
+
+export default function TokensPage() {
+ const {
+ data: tokens,
+ mutate,
+ isLoading,
+ } = useSWR<Token[]>("/api/user/tokens", fetcher);
+
+ const [createdToken, setCreatedToken] = useState<string | null>(null);
+ const { TokenCreatedModal, setShowTokenCreatedModal } = useTokenCreatedModal({
+ token: createdToken || "",
+ });
+ return (
+ <SettingsLayout>
+ <TokenCreatedModal />
+ <Form
+ title="Create New API Key"
+ description="Enter a unique name for your API key to differentiate it from other keys."
+ inputData={{
+ name: "name",
+ defaultValue: "",
+ placeholder: "Jetpack API Key",
+ maxLength: 140,
+ }}
+ helpText="Note: We do not display or store your API keys again after you generate them."
+ buttonText="Submit"
+ handleSubmit={(data) =>
+ fetch("/api/user/tokens", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(data),
+ }).then(async (res) => {
+ if (res.status === 200) {
+ const { token } = await res.json();
+ setCreatedToken(token);
+ setShowTokenCreatedModal(true);
+ mutate();
+ toast.success("Successfully created a new token!");
+ } else {
+ const errorMessage = await res.text();
+ toast.error(errorMessage || "Something went wrong");
+ }
+ })
+ }
+ />
+ <div className="rounded-lg border border-gray-200 bg-white">
+ <div className="flex flex-col space-y-3 p-5 sm:p-10">
+ <h2 className="text-xl font-medium">Your API Keys</h2>
+ <p className="text-sm text-gray-500">
+ These API keys allow other apps to access your account. Use it with
+ caution – do not share your API key with others, or expose it in the
+ browser or other client-side code
+ </p>
+ </div>
+ {isLoading || !tokens ? (
+ <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
+ <LoadingSpinner className="h-6 w-6 text-gray-500" />
+ <p className="text-sm text-gray-500">Fetching API keys...</p>
+ </div>
+ ) : tokens.length > 0 ? (
+ <div>
+ <div className="grid grid-cols-5 border-b border-gray-200 px-5 py-2 text-sm font-medium text-gray-500 sm:px-10">
+ <div className="col-span-3">Name</div>
+ <div>Key</div>
+ <div className="text-center">Last used</div>
+ </div>
+ <div className="divide-y divide-gray-200">
+ {tokens.map((token) => (
+ <TokenRow key={token.id} {...token} />
+ ))}
+ </div>
+ </div>
+ ) : (
+ <div className="flex flex-col items-center justify-center space-y-4 pb-20 pt-10">
+ <FolderOpen className="h-6 w-6 text-gray-500" />
+ <p className="text-sm text-gray-500">
+ No API keys found. Create one above.
+ </p>
+ </div>
+ )}
+ </div>
+ </SettingsLayout>
+ );
+}
+
+const TokenRow = (token: Token) => {
+ const [openPopover, setOpenPopover] = useState(false);
+ const { DeleteTokenModal, setShowDeleteTokenModal } = useDeleteTokenModal({
+ token,
+ });
+ return (
+ <>
+ <DeleteTokenModal />
+ <div className="relative grid grid-cols-5 items-center px-5 py-3 sm:px-10">
+ <div className="col-span-3 flex items-center space-x-3">
+ <TokenAvatar id={token.id} />
+ <div className="flex flex-col space-y-px">
+ <p className="font-semibold text-gray-700">{token.name}</p>
+ <p className="text-sm text-gray-500">
+ Created {timeAgo(token.createdAt, { withAgo: true })}
+ </p>
+ </div>
+ </div>
+ <div className="font-mono text-sm">{token.partialKey}</div>
+ <div className="text-center text-sm text-gray-500">
+ {timeAgo(token.lastUsed)}
+ </div>
+ <Popover
+ content={
+ <div className="grid w-full gap-1 p-2 sm:w-48">
+ <button
+ onClick={() => {
+ setOpenPopover(false);
+ setShowDeleteTokenModal(true);
+ }}
+ className="rounded-md p-2 text-left text-sm font-medium text-red-600 transition-all duration-75 hover:bg-red-600 hover:text-white"
+ >
+ <IconMenu
+ text="Delete API Key"
+ icon={<Trash className="h-4 w-4" />}
+ />
+ </button>
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <button
+ onClick={() => {
+ setOpenPopover(!openPopover);
+ }}
+ className="absolute right-4 rounded-md px-1 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <MoreVertical className="h-5 w-5 text-gray-500" />
+ </button>
+ </Popover>
+ </div>
+ </>
+ );
+};
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 86580e4365..bdd2e91907 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -23,6 +23,7 @@ model User {
sessions Session[]
projects ProjectUsers[]
links Link[]
+ tokens Token[]
createdAt DateTime @default(now())
}
@@ -64,6 +65,21 @@ model VerificationToken {
@@unique([identifier, token])
}
+model Token {
+ id String @id @default(cuid())
+ name String
+ hashedKey String @unique
+ partialKey String
+ expires DateTime?
+ lastUsed DateTime?
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ userId String
+
+ @@index([userId])
+}
+
model Project {
id String @id @default(cuid())
name String
diff --git a/yarn.lock b/yarn.lock
index 57833b6272..c00af13e22 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2422,6 +2422,27 @@
aria-hidden "^1.1.1"
react-remove-scroll "2.5.4"
+"@radix-ui/[email protected]":
+ version "1.0.3"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-dialog/-/react-dialog-1.0.3.tgz#a715bf30f35fcd80476c0a07fcc073c1968e6d3e"
+ integrity sha512-owNhq36kNPqC2/a+zJRioPg6HHnTn5B/sh/NjTY8r4W9g1L5VJlrzZIVcBr7R9Mg8iLjVmh6MGgMlfoVf/WO/A==
+ dependencies:
+ "@babel/runtime" "^7.13.10"
+ "@radix-ui/primitive" "1.0.0"
+ "@radix-ui/react-compose-refs" "1.0.0"
+ "@radix-ui/react-context" "1.0.0"
+ "@radix-ui/react-dismissable-layer" "1.0.3"
+ "@radix-ui/react-focus-guards" "1.0.0"
+ "@radix-ui/react-focus-scope" "1.0.2"
+ "@radix-ui/react-id" "1.0.0"
+ "@radix-ui/react-portal" "1.0.2"
+ "@radix-ui/react-presence" "1.0.0"
+ "@radix-ui/react-primitive" "1.0.2"
+ "@radix-ui/react-slot" "1.0.1"
+ "@radix-ui/react-use-controllable-state" "1.0.0"
+ aria-hidden "^1.1.1"
+ react-remove-scroll "2.5.5"
+
"@radix-ui/react-dialog@^1.0.4":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@radix-ui/react-dialog/-/react-dialog-1.0.4.tgz#06bce6c16bb93eb36d7a8589e665a20f4c1c52c1"
@@ -2567,9 +2588,9 @@
"@radix-ui/react-use-previous" "1.0.0"
"@radix-ui/react-visually-hidden" "1.0.2"
-"@radix-ui/react-popover@^1.0.5":
+"@radix-ui/[email protected]":
version "1.0.5"
- resolved "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.0.5.tgz"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-popover/-/react-popover-1.0.5.tgz#9c58100ed6809eb611c0acbf032f9ab58c0b55d1"
integrity sha512-GRHZ8yD12MrN2NLobHPE8Rb5uHTxd9x372DE9PPNnBjpczAQHcZ5ne0KXG4xpf+RDdXSzdLv9ym6mYJCDTaUZg==
dependencies:
"@babel/runtime" "^7.13.10"