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.

Revert "add publishable key"

Kiran Kc067d33f9a01
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
index 9523dc69a4..fef6aee9e8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
@@ -8,7 +8,6 @@ import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";
import EmptyState from "@/ui/shared/empty-state";
import { Delete } from "@/ui/shared/icons";
-import { WorkspacePublicKey } from "@/ui/workspaces/workspace-public-key";
import {
Avatar,
Badge,
@@ -25,7 +24,7 @@ import { useState } from "react";
import useSWR from "swr";
export default function TokensPageClient() {
- const { id: workspaceId, conversionEnabled } = useWorkspace();
+ const { id: workspaceId } = useWorkspace();
const { data: tokens, isLoading } = useSWR<TokenProps[]>(
`/api/tokens?workspaceId=${workspaceId}`,
fetcher,
@@ -49,11 +48,10 @@ export default function TokensPageClient() {
<>
<TokenCreatedModal />
<AddEditTokenModal />
- {conversionEnabled && <WorkspacePublicKey />}
<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">
<div className="flex max-w-screen-sm flex-col space-y-3">
- <h2 className="text-xl font-medium">Secret keys</h2>
+ <h2 className="text-xl font-medium">Workspace API Keys</h2>
<p className="text-sm text-gray-500">
These API keys allow other apps to access your workspace. Use it
with caution – do not share your API key with others, or expose it
diff --git a/apps/web/lib/actions/create-publishable-key.ts b/apps/web/lib/actions/create-publishable-key.ts
deleted file mode 100644
index b519743d1b..0000000000
--- a/apps/web/lib/actions/create-publishable-key.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-"use server";
-
-import { prisma } from "@/lib/prisma";
-import { nanoid } from "@dub/utils";
-import z from "../zod";
-import { authActionClient } from "./safe-action";
-
-const schema = z.object({
- workspaceId: z.string(),
-});
-
-// Create publishable key
-export const createPublishableKey = authActionClient
- .schema(schema)
- .action(async ({ ctx }) => {
- const { workspace } = ctx;
-
- if (!workspace.conversionEnabled) {
- throw new Error("Conversion is not enabled for this workspace.");
- }
-
- if (workspace.publishableKey) {
- throw new Error("Publishable key already exists.");
- }
-
- const publishableKey = `dub_pk_${nanoid(24)}`;
-
- await prisma.project.update({
- where: {
- id: workspace.id,
- },
- data: {
- publishableKey,
- },
- });
-
- return {
- publishableKey,
- };
- });
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index 0e093ef13f..d1571973b4 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -104,10 +104,6 @@ export const WorkspaceSchema = z
.describe(
"The feature flags of the workspace, indicating which features are enabled.",
),
- publishableKey: z
- .string()
- .nullable()
- .describe("The publishable key of the workspace."),
})
.openapi({
title: "Workspace",
diff --git a/apps/web/prisma/schema/workspace.prisma b/apps/web/prisma/schema/workspace.prisma
index b7c8734c94..3365278031 100644
--- a/apps/web/prisma/schema/workspace.prisma
+++ b/apps/web/prisma/schema/workspace.prisma
@@ -34,7 +34,6 @@ model Project {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
usageLastChecked DateTime @default(now())
- publishableKey String? @unique
users ProjectUsers[]
invites ProjectInvite[]
diff --git a/apps/web/ui/workspaces/workspace-public-key.tsx b/apps/web/ui/workspaces/workspace-public-key.tsx
deleted file mode 100644
index b6c5257a50..0000000000
--- a/apps/web/ui/workspaces/workspace-public-key.tsx
+++ /dev/null
@@ -1,68 +0,0 @@
-"use client";
-
-import { createPublishableKey } from "@/lib/actions/create-publishable-key";
-import useWorkspace from "@/lib/swr/use-workspace";
-import { Button, CopyButton } from "@dub/ui";
-import { useAction } from "next-safe-action/hooks";
-import { useState } from "react";
-import { toast } from "sonner";
-import { mutate } from "swr";
-
-export const WorkspacePublicKey = () => {
- const { id, slug, publishableKey } = useWorkspace();
-
- const [publicKey, setPublicKey] = useState<string | null>(
- publishableKey || null,
- );
-
- const { executeAsync, isExecuting } = useAction(createPublishableKey, {
- onSuccess({ data }) {
- toast.success("Publishable key created successfully.");
-
- if (data?.publishableKey) {
- setPublicKey(data.publishableKey);
- }
-
- mutate(`/api/workspaces/${slug}`);
- },
- onError({ error }) {
- toast.error(error.serverError?.serverError);
- },
- });
-
- return (
- <>
- <div className="rounded-lg border border-gray-200 bg-white">
- <div className="relative flex flex-col space-y-6 p-5 sm:p-10">
- <div className="flex flex-col space-y-3">
- <h2 className="text-xl font-medium">Publishable Key</h2>
- <p className="text-sm text-gray-500">
- This key should be used in your client-side code.{" "}
- <a
- href="https://dub.co/docs/api-reference/tokens"
- target="_blank"
- className="font-medium underline underline-offset-4 hover:text-black"
- >
- Learn more.
- </a>
- </p>
- </div>
-
- {publicKey ? (
- <div className="flex w-full max-w-md items-center justify-between rounded-md border border-gray-300 bg-white p-2">
- <p className="text-sm text-gray-500">{publicKey}</p>
- <CopyButton value={publicKey} className="rounded-md" />
- </div>
- ) : (
- <Button
- text={isExecuting ? "Creating..." : "Create publishable key"}
- loading={isExecuting}
- className="w-fit"
- onClick={() => executeAsync({ workspaceId: id! })}
- />
- )}
- </div>
- </div>
- </>
- );
-};