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.

Introduces an OAuth app created modal to display client credentials after creation,

Kiran K59ce1d9335e1
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx
index a16c94f1fc..040769527e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx
@@ -21,13 +21,12 @@ import {
import { fetcher } from "@dub/utils";
import { Trash, Upload } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
-import { redirect, useSearchParams } from "next/navigation";
+import { redirect } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import useSWR from "swr";
export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
- const searchParams = useSearchParams();
const { slug, id: workspaceId, role } = useWorkspace();
const [openPopover, setOpenPopover] = useState(false);
const { executeAsync, result, isPending } = useAction(generateClientSecret, {
@@ -170,11 +169,7 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
<>
<OAuthAppCredentials
clientId={oAuthApp.clientId}
- clientSecret={
- result.data?.clientSecret ||
- searchParams.get("client_secret") ||
- null
- }
+ clientSecret={result.data?.clientSecret || null}
partialClientSecret={oAuthApp.partialClientSecret}
/>
<hr />
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 2350528904..950b92c896 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -46,6 +46,7 @@ import {
import { dashboardSchema } from "./zod/schemas/dashboard";
import { DiscountSchema } from "./zod/schemas/discount";
import { FolderSchema } from "./zod/schemas/folders";
+import { GroupWithProgramSchema } from "./zod/schemas/group-with-program";
import {
additionalPartnerLinkSchema,
GroupSchema,
@@ -53,7 +54,6 @@ import {
GroupWithFormDataSchema,
PartnerGroupDefaultLinkSchema,
} from "./zod/schemas/groups";
-import { GroupWithProgramSchema } from "./zod/schemas/group-with-program";
import { integrationSchema } from "./zod/schemas/integration";
import { InvoiceSchema } from "./zod/schemas/invoices";
import {
@@ -79,6 +79,11 @@ import {
PayoutResponseSchema,
PayoutSchema,
} from "./zod/schemas/payouts";
+import {
+ programApplicationFormDataWithValuesSchema,
+ programApplicationFormFieldWithValuesSchema,
+ programApplicationFormSchema,
+} from "./zod/schemas/program-application-form";
import { programLanderSchema } from "./zod/schemas/program-lander";
import { programDataSchema } from "./zod/schemas/program-onboarding";
import {
@@ -117,7 +122,6 @@ import {
workflowConditionSchema,
} from "./zod/schemas/workflows";
import { workspacePreferencesSchema } from "./zod/schemas/workspace-preferences";
-import { programApplicationFormDataWithValuesSchema, programApplicationFormFieldWithValuesSchema, programApplicationFormSchema } from "./zod/schemas/program-application-form";
export type LinkProps = Link;
@@ -326,9 +330,9 @@ export type TokenProps = z.infer<typeof tokenSchema>;
export type OAuthAppProps = z.infer<typeof oAuthAppSchema>;
-export type NewOAuthApp = z.infer<typeof createOAuthAppSchema>;
+export type OAuthAppWithClientSecret = OAuthAppProps & { clientSecret: string };
-export type ExistingOAuthApp = OAuthAppProps;
+export type NewOAuthApp = z.infer<typeof createOAuthAppSchema>;
export type IntegrationProps = z.infer<typeof integrationSchema>;
@@ -455,11 +459,17 @@ export type ProgramWithLanderDataProps = z.infer<
typeof ProgramWithLanderDataSchema
>;
-export type ProgramApplicationFormData = z.infer<typeof programApplicationFormSchema>;
+export type ProgramApplicationFormData = z.infer<
+ typeof programApplicationFormSchema
+>;
-export type ProgramApplicationFormDataWithValues = z.infer<typeof programApplicationFormDataWithValuesSchema>;
+export type ProgramApplicationFormDataWithValues = z.infer<
+ typeof programApplicationFormDataWithValuesSchema
+>;
-export type ProgramApplicationFormFieldWithValues = z.infer<typeof programApplicationFormFieldWithValuesSchema>;
+export type ProgramApplicationFormFieldWithValues = z.infer<
+ typeof programApplicationFormFieldWithValuesSchema
+>;
export type ProgramInviteProps = z.infer<typeof ProgramInviteSchema>;
@@ -552,7 +562,7 @@ export type LeadEventTB = z.infer<typeof leadEventSchemaTB>;
export type SaleEventTB = z.infer<typeof saleEventSchemaTB>;
-export type GroupProps = z.infer<typeof GroupSchema>
+export type GroupProps = z.infer<typeof GroupSchema>;
export type GroupWithFormDataProps = z.infer<typeof GroupWithFormDataSchema>;
diff --git a/apps/web/ui/modals/oauth-app-created-modal.tsx b/apps/web/ui/modals/oauth-app-created-modal.tsx
new file mode 100644
index 0000000000..362cb51c65
--- /dev/null
+++ b/apps/web/ui/modals/oauth-app-created-modal.tsx
@@ -0,0 +1,156 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { OAuthAppWithClientSecret } from "@/lib/types";
+import { Button, Copy, Modal, Tick, useCopyToClipboard } from "@dub/ui";
+import { useRouter } from "next/navigation";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import { toast } from "sonner";
+
+interface OAuthAppCreatedModalProps {
+ showOAuthAppCreatedModal: boolean;
+ setShowOAuthAppCreatedModal: Dispatch<SetStateAction<boolean>>;
+ oAuthApp: OAuthAppWithClientSecret | null;
+}
+
+function OAuthAppCreatedModal({
+ showOAuthAppCreatedModal,
+ setShowOAuthAppCreatedModal,
+ oAuthApp,
+}: OAuthAppCreatedModalProps) {
+ const router = useRouter();
+ const { slug } = useWorkspace();
+ const [copied, copyToClipboard] = useCopyToClipboard();
+ const [copiedField, setCopiedField] = useState<"id" | "secret" | null>(null);
+
+ if (!oAuthApp) {
+ return null;
+ }
+
+ return (
+ <Modal
+ showModal={showOAuthAppCreatedModal}
+ setShowModal={setShowOAuthAppCreatedModal}
+ className="max-w-md"
+ >
+ <div className="space-y-2 border-b border-neutral-200 px-4 py-4 sm:px-6">
+ <h3 className="text-lg font-medium">OAuth App Created</h3>
+ <p className="text-sm text-neutral-500">
+ For security reasons, we will only show you the client secret once.
+ Please copy and store it somewhere safe.
+ </p>
+ </div>
+
+ <div className="flex flex-col space-y-4 bg-neutral-50 px-4 py-8 sm:px-6">
+ <div className="flex flex-col gap-1">
+ <h2 className="text-sm font-medium text-neutral-800">Client ID</h2>
+ <div className="flex items-center justify-between gap-2 rounded-md border border-neutral-200 bg-white p-2">
+ <p className="truncate font-mono text-sm text-neutral-500">
+ {oAuthApp.clientId}
+ </p>
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ setCopiedField("id");
+ toast.promise(copyToClipboard(oAuthApp.clientId), {
+ success: "Client ID copied to clipboard!",
+ });
+ }}
+ type="button"
+ className="text-neutral-90 flex h-7 shrink-0 items-center gap-2 rounded-md border border-neutral-200 bg-white px-2 py-1 text-xs font-medium hover:bg-neutral-50"
+ >
+ {copied && copiedField === "id" ? (
+ <Tick className="h-3.5 w-3.5" />
+ ) : (
+ <Copy className="h-3.5 w-3.5" />
+ )}
+ {copied && copiedField === "id" ? "Copied" : "Copy"}
+ </button>
+ </div>
+ </div>
+
+ <div className="flex flex-col gap-1">
+ <h2 className="text-sm font-medium text-neutral-800">
+ Client Secret
+ </h2>
+ <div className="flex items-center justify-between gap-2 rounded-md border border-neutral-200 bg-white p-2">
+ <p className="truncate font-mono text-sm text-neutral-500">
+ {oAuthApp.clientSecret}
+ </p>
+ <button
+ onClick={(e) => {
+ e.stopPropagation();
+ setCopiedField("secret");
+ toast.promise(copyToClipboard(oAuthApp.clientSecret), {
+ success: "Client Secret copied to clipboard!",
+ });
+ }}
+ type="button"
+ className="text-neutral-90 flex h-7 shrink-0 items-center gap-2 rounded-md border border-neutral-200 bg-white px-2 py-1 text-xs font-medium hover:bg-neutral-50"
+ >
+ {copied && copiedField === "secret" ? (
+ <Tick className="h-3.5 w-3.5" />
+ ) : (
+ <Copy className="h-3.5 w-3.5" />
+ )}
+ {copied && copiedField === "secret" ? "Copied" : "Copy"}
+ </button>
+ </div>
+ <span className="text-xs text-red-600">
+ Be sure to copy your client secret. You won't be able to see it
+ again.
+ </span>
+ </div>
+
+ <div className="flex gap-2">
+ <Button
+ text="Close"
+ variant="secondary"
+ onClick={() => {
+ router.push(`/${slug}/settings/oauth-apps`);
+ }}
+ className="flex-1"
+ />
+ <Button
+ text="Go to OAuth App"
+ onClick={() => {
+ router.push(`/${slug}/settings/oauth-apps/${oAuthApp.id}`);
+ }}
+ className="flex-1"
+ />
+ </div>
+ </div>
+ </Modal>
+ );
+}
+
+export function useOAuthAppCreatedModal({
+ oAuthApp,
+}: {
+ oAuthApp: OAuthAppWithClientSecret | null;
+}) {
+ const [showOAuthAppCreatedModal, setShowOAuthAppCreatedModal] =
+ useState(false);
+
+ const OAuthAppCreatedModalCallback = useCallback(() => {
+ return (
+ <OAuthAppCreatedModal
+ showOAuthAppCreatedModal={showOAuthAppCreatedModal}
+ setShowOAuthAppCreatedModal={setShowOAuthAppCreatedModal}
+ oAuthApp={oAuthApp}
+ />
+ );
+ }, [showOAuthAppCreatedModal, setShowOAuthAppCreatedModal, oAuthApp]);
+
+ return useMemo(
+ () => ({
+ setShowOAuthAppCreatedModal,
+ OAuthAppCreatedModal: OAuthAppCreatedModalCallback,
+ }),
+ [setShowOAuthAppCreatedModal, OAuthAppCreatedModalCallback],
+ );
+}
diff --git a/apps/web/ui/oauth-apps/add-edit-app-form.tsx b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
index d0ed43e82f..7dcc6c70ca 100644
--- a/apps/web/ui/oauth-apps/add-edit-app-form.tsx
+++ b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
@@ -2,7 +2,12 @@
import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
-import { ExistingOAuthApp, NewOAuthApp, OAuthAppProps } from "@/lib/types";
+import {
+ NewOAuthApp,
+ OAuthAppProps,
+ OAuthAppWithClientSecret,
+} from "@/lib/types";
+import { useOAuthAppCreatedModal } from "@/ui/modals/oauth-app-created-modal";
import {
Button,
FileUpload,
@@ -43,9 +48,14 @@ export default function AddOAuthAppForm({
const router = useRouter();
const [saving, setSaving] = useState(false);
const { slug: workspaceSlug, id: workspaceId, role } = useWorkspace();
+
+ const [createdAppData, setCreatedAppData] =
+ useState<OAuthAppWithClientSecret | null>(null);
+
const [urls, setUrls] = useState<{ id: string; value: string }[]>([
{ id: nanoid(), value: "" },
]);
+
const [screenshots, setScreenshots] = useState<
{
file?: File;
@@ -54,10 +64,15 @@ export default function AddOAuthAppForm({
}[]
>([]);
- const [data, setData] = useState<NewOAuthApp | ExistingOAuthApp>(
+ const [data, setData] = useState<NewOAuthApp | OAuthAppProps>(
oAuthApp || defaultValues,
);
+ const { OAuthAppCreatedModal, setShowOAuthAppCreatedModal } =
+ useOAuthAppCreatedModal({
+ oAuthApp: createdAppData,
+ });
+
const { error: permissionsError } = clientAccessCheck({
action: "oauth_apps.write",
role,
@@ -132,11 +147,12 @@ export default function AddOAuthAppForm({
toast.success(endpoint.successMessage);
if (endpoint.method === "POST") {
- const url = `/${workspaceSlug}/settings/oauth-apps/${result.id}${
- result.clientSecret ? `?client_secret=${result.clientSecret}` : ""
- }`;
-
- router.push(url);
+ if (result.clientSecret) {
+ setCreatedAppData(result);
+ setShowOAuthAppCreatedModal(true);
+ } else {
+ router.push(`/${workspaceSlug}/settings/oauth-apps/${result.id}`);
+ }
}
} else {
toast.error(result.error.message);
@@ -206,6 +222,7 @@ export default function AddOAuthAppForm({
return (
<>
+ <OAuthAppCreatedModal />
<form
ref={formRef}
onSubmit={onSubmit}