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.

fix installations keys

Kiran Kb17485dee27c
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 e3af9b7f61..900040ae40 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
@@ -2,6 +2,7 @@ import { DubApiError } from "@/lib/api/errors";
import { OAUTH_CONFIG } from "@/lib/api/oauth/constants";
import { createToken, generateCodeChallengeHash } from "@/lib/api/oauth/utils";
import { hashToken } from "@/lib/auth";
+import { generateRandomName } from "@/lib/names";
import { prisma } from "@/lib/prisma";
import z from "@/lib/zod";
import { authCodeExchangeSchema } from "@/lib/zod/schemas/oauth";
@@ -49,7 +50,6 @@ export const exchangeAuthCodeForToken = async (
clientId,
},
select: {
- name: true,
pkce: true,
hashedClientSecret: true,
},
@@ -208,7 +208,7 @@ export const exchangeAuthCodeForToken = async (
// Create the access token and refresh token
prisma.restrictedToken.create({
data: {
- name: `Access token for ${app.name}`,
+ name: generateRandomName(),
hashedKey: await hashToken(accessToken),
partialKey: `${accessToken.slice(0, 3)}...${accessToken.slice(-4)}`,
scopes,
diff --git a/apps/web/app/api/oauth/token/refresh-access-token.ts b/apps/web/app/api/oauth/token/refresh-access-token.ts
index 7edd4216ff..b213e17a93 100644
--- a/apps/web/app/api/oauth/token/refresh-access-token.ts
+++ b/apps/web/app/api/oauth/token/refresh-access-token.ts
@@ -2,6 +2,7 @@ import { DubApiError } from "@/lib/api/errors";
import { OAUTH_CONFIG } from "@/lib/api/oauth/constants";
import { createToken } from "@/lib/api/oauth/utils";
import { hashToken } from "@/lib/auth";
+import { generateRandomName } from "@/lib/names";
import { prisma } from "@/lib/prisma";
import z from "@/lib/zod";
import { refreshTokenSchema } from "@/lib/zod/schemas/oauth";
@@ -47,7 +48,6 @@ export const refreshAccessToken = async (
clientId,
},
select: {
- name: true,
pkce: true,
hashedClientSecret: true,
},
@@ -153,7 +153,7 @@ export const refreshAccessToken = async (
// Create the access token and refresh token
prisma.restrictedToken.create({
data: {
- name: accessToken.name,
+ name: generateRandomName(),
hashedKey: await hashToken(newAccessToken),
partialKey: `${newAccessToken.slice(0, 3)}...${newAccessToken.slice(-4)}`,
scopes: accessToken.scopes,
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx
index 5413019664..f96c6a515a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/page.tsx
@@ -9,17 +9,17 @@ export default async function IntegrationPage({
}: {
params: { slug: string; integrationSlug: string };
}) {
- const integration = await prisma.oAuthApp.findUnique({
+ const integration = await prisma.integration.findUnique({
where: {
slug: params.integrationSlug,
},
include: {
_count: {
select: {
- authorizedApps: true,
+ installations: true,
},
},
- authorizedApps: {
+ installations: {
where: {
project: {
slug: params.slug,
@@ -47,17 +47,17 @@ export default async function IntegrationPage({
integration={{
...integration,
screenshots: integration.screenshots as string[],
- installations: integration._count.authorizedApps,
+ installations: integration._count.installations,
installed:
- integration.authorizedApps.length > 0
+ integration.installations.length > 0
? {
- id: integration.authorizedApps[0].id,
+ id: integration.installations[0].id,
by: {
- id: integration.authorizedApps[0].userId,
- name: integration.authorizedApps[0].user.name,
- image: integration.authorizedApps[0].user.image,
+ id: integration.installations[0].userId,
+ name: integration.installations[0].user.name,
+ image: integration.installations[0].user.image,
},
- createdAt: integration.authorizedApps[0].createdAt,
+ createdAt: integration.installations[0].createdAt,
}
: null,
}}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page.tsx
index 022906d8cc..71faee525e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/page.tsx
@@ -18,14 +18,14 @@ export default async function IntegrationsPage() {
}
const Integrations = async () => {
- const integrations = await prisma.oAuthApp.findMany({
+ const integrations = await prisma.integration.findMany({
where: {
verified: true,
},
include: {
_count: {
select: {
- authorizedApps: true,
+ installations: true,
},
},
},
@@ -35,7 +35,7 @@ const Integrations = async () => {
<IntegrationsPageClient
integrations={integrations.map((integration) => ({
...integration,
- installations: integration._count.authorizedApps,
+ installations: integration._count.installations,
}))}
/>
);