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 to authorized apps

Kiran K0597698027d1
diff --git a/apps/web/app/api/oauth-apps/authorized/route.ts b/apps/web/app/api/oauth-apps/authorized/route.ts
index dc626b4607..f4c40d4118 100644
--- a/apps/web/app/api/oauth-apps/authorized/route.ts
+++ b/apps/web/app/api/oauth-apps/authorized/route.ts
@@ -1,33 +1,35 @@
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
-import z from "@/lib/zod";
-import { authorizedAppSchema } from "@/lib/zod/schemas/oauth";
import { NextResponse } from "next/server";
// GET /api/oauth-apps/authorized - applications authorized to access workspace resources
export const GET = withWorkspace(
async ({ workspace }) => {
- const appsAuthorized = await prisma.oAuthClient.findMany({
+ const appsAuthorized = await prisma.oAuthAuthorizedApp.findMany({
where: {
- accessTokens: {
- some: {
- projectId: workspace.id,
- },
- },
+ projectId: workspace.id,
},
select: {
- clientId: true,
- name: true,
- developer: true,
- website: true,
- scopes: true,
+ id: true,
createdAt: true,
+ oAuthClient: {
+ select: {
+ clientId: true,
+ name: true,
+ developer: true,
+ website: true,
+ },
+ },
+ user: {
+ select: {
+ id: true,
+ name: true,
+ },
+ },
},
});
- return NextResponse.json(
- z.array(authorizedAppSchema).parse(appsAuthorized),
- );
+ return NextResponse.json(appsAuthorized);
},
{
requiredScopes: ["workspaces.read"],
diff --git a/apps/web/app/api/oauth/token/exchange-code-for-token.ts b/apps/web/app/api/oauth/token/exchange-code-for-token.ts
index 908ef5d289..975915f569 100644
--- a/apps/web/app/api/oauth/token/exchange-code-for-token.ts
+++ b/apps/web/app/api/oauth/token/exchange-code-for-token.ts
@@ -138,6 +138,15 @@ export const exchangeAuthCodeForToken = async (
code,
},
}),
+
+ // Add to authorized apps
+ prisma.oAuthAuthorizedApp.create({
+ data: {
+ clientId,
+ userId,
+ projectId,
+ },
+ }),
]);
const response = {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page-client.tsx
index 65162f222d..28aa53bc5a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page-client.tsx
@@ -3,10 +3,11 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAuthorizedAppProps } from "@/lib/types";
import EmptyState from "@/ui/shared/empty-state";
+import { 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 { fetcher, formatDate } from "@dub/utils";
+import { MoreVertical } from "lucide-react";
import { useState } from "react";
import useSWR from "swr";
@@ -41,8 +42,8 @@ export default function AuthorizedAppsPageClient() {
<div className="col-span-3">Name</div>
</div>
<div className="divide-y divide-gray-200">
- {apps.map((token) => (
- <AppRow key={token.clientId} {...token} />
+ {apps.map((app) => (
+ <AppRow key={app.id} {...app} />
))}
</div>
</div>
@@ -66,12 +67,14 @@ const AppRow = (app: OAuthAuthorizedAppProps) => {
<>
<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={app.clientId} />
+ <TokenAvatar id={app.oAuthClient.name} />
<div className="flex flex-col space-y-px">
- <p className="font-semibold text-gray-700">{app.name}</p>
+ <p className="font-semibold text-gray-700">
+ {app.oAuthClient.name}
+ </p>
<div className="flex items-center gap-x-2">
<p className="text-sm text-gray-500" suppressHydrationWarning>
- {app.createdAt!}
+ Authorized by {app.user.name} on {formatDate(app.createdAt)}
</p>
</div>
</div>
@@ -83,10 +86,11 @@ const AppRow = (app: OAuthAuthorizedAppProps) => {
<Button
text="Disconnect"
variant="danger-outline"
- icon={<Edit3 className="h-4 w-4" />}
+ icon={<Delete className="h-4 w-4" />}
className="h-9 justify-start px-2 font-medium"
onClick={() => {
setOpenPopover(false);
+ alert("Not implemented yet");
}}
/>
</div>
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index e573444fd2..a6880d1ea2 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -3,7 +3,10 @@ import { metaTagsSchema } from "@/lib/zod/schemas/metatags";
import { DirectorySyncProviders } from "@boxyhq/saml-jackson";
import { Link } from "@prisma/client";
import { createLinkBodySchema } from "./zod/schemas/links";
-import { authorizedAppSchema, oAuthClientSchema } from "./zod/schemas/oauth";
+import {
+ oAuthAuthorizedAppSchema,
+ oAuthClientSchema,
+} from "./zod/schemas/oauth";
import { tokenSchema } from "./zod/schemas/token";
export type LinkProps = Link;
@@ -198,6 +201,8 @@ export type TokenProps = z.infer<typeof tokenSchema>;
export type OAuthAppProps = z.infer<typeof oAuthClientSchema>;
-export type OAuthAuthorizedAppProps = z.infer<typeof authorizedAppSchema> & {
+export type OAuthAuthorizedAppProps = z.infer<
+ typeof oAuthAuthorizedAppSchema
+> & {
createdAt: string;
};
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index 5792b5e1c2..4c90251ef1 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -84,16 +84,17 @@ export const tokenGrantSchema = z.discriminatedUnion(
},
);
-export const authorizedAppSchema = oAuthClientSchema
- .pick({
+export const oAuthAuthorizedAppSchema = z.object({
+ id: z.string(),
+ createdAt: z.date(),
+ oAuthClient: oAuthClientSchema.pick({
clientId: true,
name: true,
developer: true,
website: true,
- scopes: true,
- })
- .merge(
- z.object({
- createdAt: z.date(),
- }),
- );
+ }),
+ user: z.object({
+ id: z.string(),
+ name: z.string(),
+ }),
+});
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 89c1e6ca8d..2287da6b95 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -369,7 +369,6 @@ model OAuthClient {
name String
developer String
website String
- description String? // not used
clientSecretHashed String
redirectUri String
scopes String