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.

update the variable names

Kiran Kef9c8be320d4
diff --git a/apps/web/app/api/oauth-apps/[appId]/route.ts b/apps/web/app/api/oauth-clients/[id]/route.ts
similarity index 58%
rename from apps/web/app/api/oauth-apps/[appId]/route.ts
rename to apps/web/app/api/oauth-clients/[id]/route.ts
index c75e644bd4..d29d4a1b3e 100644
--- a/apps/web/app/api/oauth-apps/[appId]/route.ts
+++ b/apps/web/app/api/oauth-clients/[id]/route.ts
@@ -2,15 +2,18 @@ import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
-import { oAuthAppSchema, updateOAuthAppSchema } from "@/lib/zod/schemas/oauth";
+import {
+ oAuthClientSchema,
+ updateOAuthClientSchema,
+} from "@/lib/zod/schemas/oauth";
import { NextResponse } from "next/server";
-// GET /api/oauth-apps/[appId] – get an OAuth app
+// GET /api/oauth-clients/[id] – get an OAuth client
export const GET = withWorkspace(
async ({ params, workspace }) => {
- const app = await prisma.oAuthApp.findFirst({
+ const app = await prisma.oAuthClient.findFirst({
where: {
- id: params.appId,
+ id: params.id,
projectId: workspace.id,
},
});
@@ -18,26 +21,26 @@ export const GET = withWorkspace(
if (!app) {
throw new DubApiError({
code: "not_found",
- message: `OAuth app with id ${params.appId} not found.`,
+ message: `OAuth app with id ${params.id} not found.`,
});
}
- return NextResponse.json(oAuthAppSchema.parse(app));
+ return NextResponse.json(oAuthClientSchema.parse(app));
},
{
requiredScopes: ["oauth_apps.read"],
},
);
-// PATCH /api/oauth-apps/[appId] – update an OAuth app
+// PATCH /api/oauth-clients/[id] – update an OAuth client
export const PATCH = withWorkspace(
async ({ req, params, workspace }) => {
const { name, description, website, redirectUri, scopes } =
- updateOAuthAppSchema.parse(await parseRequestBody(req));
+ updateOAuthClientSchema.parse(await parseRequestBody(req));
- const app = await prisma.oAuthApp.update({
+ const app = await prisma.oAuthClient.update({
where: {
- id: params.appId,
+ id: params.id,
projectId: workspace.id,
},
data: {
@@ -51,19 +54,19 @@ export const PATCH = withWorkspace(
},
});
- return NextResponse.json(oAuthAppSchema.parse(app));
+ return NextResponse.json(oAuthClientSchema.parse(app));
},
{
requiredScopes: ["oauth_apps.write"],
},
);
-// DELETE /api/oauth-apps/[appId] - delete an OAuth app
+// DELETE /api/oauth-clients/[id] - delete an OAuth client
export const DELETE = withWorkspace(
- async ({ req, params, workspace }) => {
- const app = await prisma.oAuthApp.findFirst({
+ async ({ params, workspace }) => {
+ const app = await prisma.oAuthClient.findFirst({
where: {
- id: params.appId,
+ id: params.id,
projectId: workspace.id,
},
});
@@ -71,17 +74,17 @@ export const DELETE = withWorkspace(
if (!app) {
throw new DubApiError({
code: "not_found",
- message: `OAuth app with id ${params.appId} not found.`,
+ message: `OAuth app with id ${params.id} not found.`,
});
}
- await prisma.oAuthApp.delete({
+ await prisma.oAuthClient.delete({
where: {
- id: params.appId,
+ id: params.id,
},
});
- return NextResponse.json({ id: params.appId });
+ return NextResponse.json({ id: params.id });
},
{
requiredScopes: ["oauth_apps.write"],
diff --git a/apps/web/app/api/oauth-apps/route.ts b/apps/web/app/api/oauth-clients/route.ts
similarity index 69%
rename from apps/web/app/api/oauth-apps/route.ts
rename to apps/web/app/api/oauth-clients/route.ts
index 8ec47a079c..7228e77b14 100644
--- a/apps/web/app/api/oauth-apps/route.ts
+++ b/apps/web/app/api/oauth-clients/route.ts
@@ -2,20 +2,23 @@ import { TOKEN_LENGTH } from "@/lib/api/oauth";
import { parseRequestBody } from "@/lib/api/utils";
import { hashToken, withWorkspace } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
-import { createOAuthAppSchema, oAuthAppSchema } from "@/lib/zod/schemas/oauth";
+import {
+ createOAuthClientSchema,
+ oAuthClientSchema,
+} from "@/lib/zod/schemas/oauth";
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-clients - create a new OAuth client
export const POST = withWorkspace(
async ({ req, workspace }) => {
const { name, description, website, redirectUri, scopes } =
- createOAuthAppSchema.parse(await parseRequestBody(req));
+ createOAuthClientSchema.parse(await parseRequestBody(req));
const clientSecret = `dub_${nanoid(TOKEN_LENGTH.clientSecret)}`;
- const app = await prisma.oAuthApp.create({
+ const client = await prisma.oAuthClient.create({
data: {
projectId: workspace.id,
name,
@@ -31,7 +34,7 @@ export const POST = withWorkspace(
return NextResponse.json(
{
- ...oAuthAppSchema.parse(app),
+ ...oAuthClientSchema.parse(client),
clientSecret,
},
{ status: 201 },
@@ -42,16 +45,16 @@ export const POST = withWorkspace(
},
);
-// GET /api/oauth-apps - get all OAuth apps for a specific workspace
+// GET /api/oauth-clients - get all OAuth clients for a specific workspace
export const GET = withWorkspace(
async ({ workspace }) => {
- const apps = await prisma.oAuthApp.findMany({
+ const clients = await prisma.oAuthClient.findMany({
where: {
projectId: workspace.id,
},
});
- return NextResponse.json(z.array(oAuthAppSchema).parse(apps));
+ return NextResponse.json(z.array(oAuthClientSchema).parse(clients));
},
{
requiredScopes: ["oauth_apps.read"],
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index 66cef11a85..79b0a65680 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -1,7 +1,7 @@
import { availableScopes } from "@/lib/api/tokens/scopes";
import { z } from "zod";
-export const oAuthAppSchema = z.object({
+export const oAuthClientSchema = z.object({
id: z.string(),
name: z.string(),
description: z.string().nullable(),
@@ -14,7 +14,7 @@ export const oAuthAppSchema = z.object({
clientId: z.string(),
});
-export const createOAuthAppSchema = z.object({
+export const createOAuthClientSchema = z.object({
name: z.string().min(1).max(255),
description: z.string().max(255).nullable(),
website: z.string().url().max(255),
@@ -22,7 +22,7 @@ export const createOAuthAppSchema = z.object({
scopes: z.array(z.enum(availableScopes)).default([]).optional(),
});
-export const updateOAuthAppSchema = createOAuthAppSchema.partial();
+export const updateOAuthClientSchema = createOAuthClientSchema.partial();
// Schema for OAuth2.0 Authorization request
export const authorizeSchema = z.object({