The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
copy client id
Kiran Kb598bb46cd70
diff --git a/apps/web/app/api/oauth-apps/route.ts b/apps/web/app/api/oauth-apps/route.tsindex 9d0072d6a7..3e4dc73045 100644--- a/apps/web/app/api/oauth-apps/route.ts+++ b/apps/web/app/api/oauth-apps/route.ts@@ -16,7 +16,7 @@ export const POST = withWorkspace(const { name, developer, website, redirectUri, scopes } =createOAuthClientSchema.parse(await parseRequestBody(req));- const clientSecret = `dub_${nanoid(TOKEN_LENGTH.clientSecret)}`;+ const clientSecret = `dub_secret_${nanoid(TOKEN_LENGTH.clientSecret)}`;const client = await prisma.oAuthClient.create({data: {diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsxindex ac2ffdff71..715548f1cf 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/page-client.tsx@@ -3,14 +3,15 @@import useWorkspace from "@/lib/swr/use-workspace";import { OAuthAppProps } from "@/lib/types";import { useAddEditAppModal } from "@/ui/modals/add-edit-oauth-app-modal";-import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";+import { useAppCreatedModal } from "@/ui/modals/oauth-app-created-modal";import EmptyState from "@/ui/shared/empty-state";-import { Delete } from "@/ui/shared/icons";+import { CheckCircleFill, Delete } from "@/ui/shared/icons";import { Button, LoadingSpinner, Popover, TokenAvatar } from "@dub/ui";import { Key } from "@dub/ui/src/icons";import { fetcher } from "@dub/utils";-import { Edit3, MoreVertical } from "lucide-react";+import { Copy, Edit3, MoreVertical } from "lucide-react";import { useState } from "react";+import { toast } from "sonner";import useSWR from "swr";export default function OAuthAppPageClient() {@@ -20,15 +21,16 @@ export default function OAuthAppPageClient() {fetcher,);- const [createdToken, setCreatedToken] = useState<string | null>(null);-- const { TokenCreatedModal, setShowTokenCreatedModal } = useTokenCreatedModal({- token: createdToken || "",+ const [app, setApp] = useState<OAuthAppProps | null>(null);+ const { AppCreatedModal, setShowAppCreatedModal } = useAppCreatedModal({+ app,});- const onAppCreated = (token: string) => {- setCreatedToken(token);- setShowTokenCreatedModal(true);+ const onAppCreated = (app: OAuthAppProps) => {+ if (!app) return;++ setApp(app);+ setShowAppCreatedModal(true);};const { AddEditAppModal, AddAppButton } = useAddEditAppModal({@@ -37,7 +39,7 @@ export default function OAuthAppPageClient() {return (<>- <TokenCreatedModal />+ <AppCreatedModal /><AddEditAppModal /><div className="rounded-lg border border-gray-200 bg-white"><div className="flex flex-col items-center justify-between gap-4 space-y-3 border-b border-gray-200 p-5 sm:flex-row sm:space-y-0 sm:p-10">@@ -88,8 +90,8 @@ export default function OAuthAppPageClient() {}const AppRow = (app: OAuthAppProps) => {+ const [copiedClientId, setCopiedClientId] = useState(false);const [openPopover, setOpenPopover] = useState(false);-const { AddEditAppModal, setShowAddEditAppModal } = useAddEditAppModal({app,});@@ -98,6 +100,13 @@ const AppRow = (app: OAuthAppProps) => {// token,// });+ const copyClientId = () => {+ navigator.clipboard.writeText(app.clientId);+ setCopiedClientId(true);+ toast.success("Client ID copied!");+ setTimeout(() => setCopiedClientId(false), 3000);+ };+return (<><AddEditAppModal />@@ -128,6 +137,19 @@ const AppRow = (app: OAuthAppProps) => {setShowAddEditAppModal(true);}}/>+ <Button+ text="Copy Client ID"+ variant="outline"+ icon={+ copiedClientId ? (+ <CheckCircleFill className="h-4 w-4" />+ ) : (+ <Copy className="h-4 w-4" />+ )+ }+ className="h-9 justify-start px-2 font-medium"+ onClick={() => copyClientId()}+ /><Buttontext="Delete App"variant="danger-outline"diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.tsindex 5bf8211397..981ef1aa53 100644--- a/apps/web/lib/zod/schemas/oauth.ts+++ b/apps/web/lib/zod/schemas/oauth.ts@@ -3,6 +3,7 @@ import { z } from "zod";export const oAuthClientSchema = z.object({clientId: z.string(),+ clientSecret: z.string().optional(),name: z.string(),developer: z.string(),website: z.string(),diff --git a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx b/apps/web/ui/modals/add-edit-oauth-app-modal.tsxindex ecb2fc12f0..589a417a42 100644--- a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx+++ b/apps/web/ui/modals/add-edit-oauth-app-modal.tsx@@ -30,11 +30,11 @@ import { toast } from "sonner";import { mutate } from "swr";const newApp: OAuthAppProps = {- name: "",- developer: "",- website: "",+ name: "Supa",+ developer: "Kiran",+ website: "https://app.dub.co/acme/settings/tokens",clientId: "",- redirectUri: "",+ redirectUri: "https://app.dub.co/acme/settings/tokens",scopes: [],};@@ -47,7 +47,7 @@ function AddEditAppModal({showAddEditAppModal: boolean;setShowAddEditAppModal: Dispatch<SetStateAction<boolean>>;app?: OAuthAppProps;- onAppCreated?: (App: string) => void;+ onAppCreated?: (App: OAuthAppProps) => void;}) {const [saving, setSaving] = useState(false);const [data, setData] = useState<OAuthAppProps>(app || newApp);@@ -94,7 +94,7 @@ function AddEditAppModal({if (response.ok) {mutate(`/api/oauth-apps?workspaceId=${workspaceId}`);toast.success(endpoint.successMessage);- onAppCreated?.(result.App);+ onAppCreated?.(result);setShowAddEditAppModal(false);} else {toast.error(result.error.message);@@ -102,13 +102,13 @@ function AddEditAppModal({}};- const { name, developer, website, redirectUri, scopes } = data;+ const { name, developer, website, redirectUri } = data;const buttonDisabled =!name ||!developer ||!website ||!redirectUri ||- Object.values(scopes).filter((v) => v).length === 0;+ Object.values(selectedScopes).filter((v) => v).length === 0;return (<>@@ -130,7 +130,7 @@ function AddEditAppModal({<Logo />)}<h1 className="text-lg font-medium">- {app ? "Edit" : "Add New"} OAuth Application+ {app ? "Update" : "Add New"} OAuth Application</h1></div>@@ -310,7 +310,7 @@ export function useAddEditAppModal(onAppCreated,}: {app?: OAuthAppProps;- onAppCreated?: (App: string) => void;+ onAppCreated?: (App: OAuthAppProps) => void;} = { onAppCreated: () => {} },) {const [showAddEditAppModal, setShowAddEditAppModal] = useState(false);diff --git a/apps/web/ui/modals/oauth-app-created-modal.tsx b/apps/web/ui/modals/oauth-app-created-modal.tsxnew file mode 100644index 0000000000..7fdfcc4847--- /dev/null+++ b/apps/web/ui/modals/oauth-app-created-modal.tsx@@ -0,0 +1,94 @@+import { OAuthAppProps } from "@/lib/types";+import { Button, CopyButton, Logo, Modal } from "@dub/ui";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";++function AppCreatedModal({+ showAppCreatedModal,+ setShowAppCreatedModal,+ app,+}: {+ showAppCreatedModal: boolean;+ setShowAppCreatedModal: Dispatch<SetStateAction<boolean>>;+ app: OAuthAppProps | null;+}) {+ if (!app) {+ return null;+ }++ console.log("AppCreatedModal rendered", app);++ return (+ <Modal+ showModal={showAppCreatedModal}+ setShowModal={setShowAppCreatedModal}+ >+ <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">{app.name}</h3>+ <p className="text-center text-sm text-gray-500">+ Be sure to copy your client secret. You won’t be able to see it again.+ </p>+ </div>++ <div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-10">+ <div className="space-y-2">+ <label className="text-sm font-medium text-gray-500">Client ID</label>+ <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">{app.clientId}</p>+ <div className="flex flex-col gap-2">+ <CopyButton value={app.clientId} className="rounded-md" />+ </div>+ </div>+ </div>++ <div className="space-y-2">+ <label className="text-sm font-medium text-gray-500">+ Client Secret+ </label>+ <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 text-nowrap">+ {app.clientSecret}+ </p>+ <div className="flex flex-col gap-2">+ <CopyButton value={app.clientSecret!} className="rounded-md" />+ </div>+ </div>+ </div>++ <Button+ text="Done"+ variant="secondary"+ onClick={() => setShowAppCreatedModal(false)}+ />+ </div>+ </Modal>+ );+}++export function useAppCreatedModal({ app }: { app: OAuthAppProps | null }) {+ const [showAppCreatedModal, setShowAppCreatedModal] = useState(false);++ const AppCreatedModalCallback = useCallback(() => {+ return (+ <AppCreatedModal+ showAppCreatedModal={showAppCreatedModal}+ setShowAppCreatedModal={setShowAppCreatedModal}+ app={app}+ />+ );+ }, [showAppCreatedModal, setShowAppCreatedModal]);++ return useMemo(+ () => ({+ setShowAppCreatedModal,+ AppCreatedModal: AppCreatedModalCallback,+ }),+ [setShowAppCreatedModal, AppCreatedModalCallback],+ );+}