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.

add clientAccessCheck to OAuth apps UIs

Kiran K5f5d8e1ac628
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx
index 8c6ab90a1e..90eb0faaea 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/new/page-client.tsx
@@ -8,7 +8,7 @@ import Link from "next/link";
import { redirect } from "next/navigation";
export default function NewOAuthAppPageClient() {
- const { slug, flags } = useWorkspace();
+ const { slug, flags, role } = useWorkspace();
if (!flags?.integrations) {
redirect(`/${slug}/settings`);
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.tsx
index 78ada97427..59022a5a6c 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
@@ -1,19 +1,20 @@
"use client";
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAppProps } from "@/lib/types";
import OAuthAppCard from "@/ui/oauth-apps/oauth-app-card";
import OAuthAppPlaceholder from "@/ui/oauth-apps/oauth-app-placeholder";
import EmptyState from "@/ui/shared/empty-state";
-import { buttonVariants, Cube, TooltipContent } from "@dub/ui";
+import { Button, Cube, TooltipContent } from "@dub/ui";
import { InfoTooltip } from "@dub/ui/src/tooltip";
-import { cn, fetcher } from "@dub/utils";
-import Link from "next/link";
-import { redirect } from "next/navigation";
+import { fetcher } from "@dub/utils";
+import { redirect, useRouter } from "next/navigation";
import useSWR from "swr";
export default function OAuthAppsPageClient() {
- const { slug, id: workspaceId, flags } = useWorkspace();
+ const router = useRouter();
+ const { slug, id: workspaceId, flags, role } = useWorkspace();
if (!flags?.integrations) {
redirect(`/${slug}/settings`);
@@ -24,6 +25,12 @@ export default function OAuthAppsPageClient() {
fetcher,
);
+ const permissionsError = clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ customPermissionDescription: "manage OAuth applications",
+ }).error;
+
return (
<div className="grid gap-5">
<div className="flex flex-wrap justify-between gap-6">
@@ -43,15 +50,12 @@ export default function OAuthAppsPageClient() {
/>
</div>
<div className="flex w-full items-center gap-3 sm:w-auto">
- <Link
- href={`/${slug}/settings/oauth-apps/new`}
- className={cn(
- buttonVariants({ variant: "primary" }),
- "flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",
- )}
- >
- Add OAuth App
- </Link>
+ <Button
+ className="flex h-10 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm"
+ text="Add OAuth App"
+ onClick={() => router.push(`/${slug}/settings/oauth-apps/new`)}
+ disabledTooltip={permissionsError}
+ />
</div>
</div>