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 app creation

Kiran K3db4997aa78e
diff --git a/apps/web/app/api/oauth-apps/[appId]/route.ts b/apps/web/app/api/oauth-apps/[appId]/route.ts
index c1b0ed268e..c6e3bd9edc 100644
--- a/apps/web/app/api/oauth-apps/[appId]/route.ts
+++ b/apps/web/app/api/oauth-apps/[appId]/route.ts
@@ -10,7 +10,7 @@ import { NextResponse } from "next/server";
// GET /api/oauth-apps/[appId] – get an OAuth app
export const GET = withWorkspace(async ({ params, workspace }) => {
- const app = await prisma.oAuthClient.findUnique({
+ const app = await prisma.oAuthApp.findUnique({
where: {
id: params.appId,
projectId: workspace.id,
@@ -24,7 +24,7 @@ export const GET = withWorkspace(async ({ params, workspace }) => {
});
}
- return NextResponse.json(app);
+ return NextResponse.json(oAuthAppSchema.parse(app));
});
// PATCH /api/oauth-apps/[appId] – update an OAuth app
@@ -32,7 +32,7 @@ export const PATCH = withWorkspace(async ({ req, params, workspace }) => {
const { name, description, website, redirectUri, scopes } =
updateOAuthAppSchema.parse(await parseRequestBody(req));
- const app = await prisma.oAuthClient.update({
+ const app = await prisma.oAuthApp.update({
where: {
id: params.appId,
projectId: workspace.id,
@@ -51,7 +51,7 @@ export const PATCH = withWorkspace(async ({ req, params, workspace }) => {
// DELETE /api/oauth-apps/[appId] - delete an OAuth app
export const DELETE = withWorkspace(async ({ req, params, workspace }) => {
- const app = await prisma.oAuthClient.findUnique({
+ const app = await prisma.oAuthApp.findUnique({
where: {
id: params.appId,
projectId: workspace.id,
@@ -65,7 +65,7 @@ export const DELETE = withWorkspace(async ({ req, params, workspace }) => {
});
}
- await prisma.oAuthClient.delete({
+ await prisma.oAuthApp.delete({
where: {
id: params.appId,
},
diff --git a/apps/web/app/api/oauth-apps/route.ts b/apps/web/app/api/oauth-apps/route.ts
index 035d3afb61..5bd55bd6ed 100644
--- a/apps/web/app/api/oauth-apps/route.ts
+++ b/apps/web/app/api/oauth-apps/route.ts
@@ -10,14 +10,14 @@ import { nanoid } from "@dub/utils";
import { NextResponse } from "next/server";
import { z } from "zod";
-// POST /api/oauth-apps - create a new oauth app
+// POST /api/oauth-apps - create a new OAuth app
export const POST = withWorkspace(async ({ req, workspace }) => {
const { name, description, website, redirectUri, scopes } =
createOAuthAppSchema.parse(await parseRequestBody(req));
const clientSecret = `dub_${nanoid(TOKEN_LENGTHS.clientSecret)}`;
- const app = await prisma.oAuthClient.create({
+ const app = await prisma.oAuthApp.create({
data: {
projectId: workspace.id,
name,
@@ -39,9 +39,9 @@ export const POST = withWorkspace(async ({ req, workspace }) => {
);
});
-// GET /api/oauth-apps - get all oauth apps for a specific workspace
-export const GET = withWorkspace(async ({ req, workspace }) => {
- const apps = await prisma.oAuthClient.findMany({
+// GET /api/oauth-apps - get all OAuth apps for a specific workspace
+export const GET = withWorkspace(async ({ workspace }) => {
+ const apps = await prisma.oAuthApp.findMany({
where: {
projectId: workspace.id,
},
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 501d45b74e..d60dcf7d8c 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -145,6 +145,7 @@ model Project {
customers Customer[]
defaultDomains DefaultDomains[]
restrictedTokens RestrictedToken[]
+ apps OAuthApp[]
@@index(usageLastChecked(sort: Asc))
}
@@ -221,7 +222,7 @@ model Domain {
lastClicked DateTime? // when the link was last clicked
publicStats Boolean @default(false)
description String?
- noindex Boolean @default(false)
+ noindex Boolean @default(false)
// these attributes will exist on both Link and Domain models
createdAt DateTime @default(now())
@@ -396,9 +397,7 @@ model OAuthApp {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
- codes OAuthCode[]
- accessTokens OAuthAccessToken[]
+ project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
@@index(projectId)
}
@@ -406,44 +405,11 @@ model OAuthApp {
model OAuthCode {
id String @id @default(cuid())
clientId String
- userId String
- projectId String // Workspace user granted access to
+ userId String // User who granted access
+ projectId String // Workspace that user granted access to
code String @unique
+ scopes String?
redirectUri String
expiresAt DateTime
createdAt DateTime @default(now())
-
- project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
- client OAuthClient @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
-
- @@index([clientId, code])
-}
-
-model OAuthAccessToken {
- id String @id @default(cuid())
- clientId String
- userId String
- accessToken String @unique
- expiresAt DateTime
- createdAt DateTime @default(now())
-
- user User @relation(fields: [userId], references: [id], onDelete: Cascade)
- client OAuthClient @relation(fields: [clientId], references: [clientId], onDelete: Cascade)
- refreshTokens OAuthRefreshToken[]
-
- @@index(clientId)
- @@index(userId)
-}
-
-model OAuthRefreshToken {
- id String @id @default(cuid())
- accessTokenId String
- refreshToken String @unique
- expiresAt DateTime
- createdAt DateTime @default(now())
-
- accessToken OAuthAccessToken @relation(fields: [accessTokenId], references: [id], onDelete: Cascade)
-
- @@index(accessTokenId)
}