The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix the installed integrations
Kiran K359c5cfd30db
diff --git a/apps/web/app/api/integrations/uninstall/route.ts b/apps/web/app/api/integrations/uninstall/route.tsindex 2fda13b45b..d6c1d15527 100644--- a/apps/web/app/api/integrations/uninstall/route.ts+++ b/apps/web/app/api/integrations/uninstall/route.ts@@ -8,7 +8,7 @@ export const DELETE = withWorkspace(async ({ searchParams, session }) => {const { installationId } = searchParams;- const installation = await prisma.oAuthAuthorizedApp.findUnique({+ const installation = await prisma.installedIntegration.findUnique({where: {id: installationId,},@@ -29,7 +29,7 @@ export const DELETE = withWorkspace(});}- await prisma.oAuthAuthorizedApp.delete({+ await prisma.installedIntegration.delete({where: {id: installationId,},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.tsindex bdf1958736..f9cc43eb04 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@@ -56,7 +56,7 @@ export const exchangeAuthCodeForToken = async (},});- if (!app) {+ if (!app || !app.integrationId) {throw new DubApiError({code: "unauthorized",message: "OAuth app not found for the provided client_id",@@ -158,8 +158,6 @@ export const exchangeAuthCodeForToken = async (},});- const { userId, projectId, scopes } = accessCode;-const accessToken = createToken({length: OAUTH_CONFIG.ACCESS_TOKEN_LENGTH,prefix: OAUTH_CONFIG.ACCESS_TOKEN_PREFIX,@@ -173,20 +171,23 @@ export const exchangeAuthCodeForToken = async (Date.now() + OAUTH_CONFIG.ACCESS_TOKEN_LIFETIME * 1000,);+ const { userId, projectId, scopes } = accessCode;+ const { integrationId } = app;+// Install the app// We only support one token per client per user per workspace at a time- const installation = await prisma.oAuthAuthorizedApp.upsert({+ const installation = await prisma.installedIntegration.upsert({create: {userId,projectId,- clientId,+ integrationId,},update: {},where: {- userId_projectId_clientId: {+ userId_integrationId_projectId: {userId,projectId,- clientId,+ integrationId,},},});diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.tsindex 04edc3d2ca..a15ef6f246 100644--- a/apps/web/lib/zod/schemas/oauth.ts+++ b/apps/web/lib/zod/schemas/oauth.ts@@ -137,24 +137,3 @@ export const tokenGrantSchema = z.discriminatedUnion(}),},);--// Schema to represent an authorized OAuth app with user-export const oAuthAuthorizedAppSchema = z- .object({- id: z.string(),- createdAt: z.date(),- user: z.object({- id: z.string(),- name: z.string(),- }),- })- .merge(- oAuthAppSchema.pick({- clientId: true,- name: true,- slug: true,- developer: true,- website: true,- logo: true,- }),- );