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 /api/projects and /api/me, fix OpenAPI spec typos

Steven Teyd4dd99a11386
diff --git a/apps/web/app/api/me/route.ts b/apps/web/app/api/me/route.ts
new file mode 100644
index 0000000000..42c9c9f0aa
--- /dev/null
+++ b/apps/web/app/api/me/route.ts
@@ -0,0 +1,7 @@
+import { withAuth } from "@/lib/auth";
+import { NextResponse } from "next/server";
+
+// GET /api/me - get the current user
+export const GET = withAuth(async ({ session }) => {
+ return NextResponse.json(session.user);
+});
diff --git a/apps/web/app/api/projects/route.ts b/apps/web/app/api/projects/route.ts
index dd297bf864..2299f5643f 100644
--- a/apps/web/app/api/projects/route.ts
+++ b/apps/web/app/api/projects/route.ts
@@ -9,6 +9,20 @@ import { isReservedKey } from "@/lib/edge-config";
import prisma from "@/lib/prisma";
import { DEFAULT_REDIRECTS, validSlugRegex } from "@dub/utils";
+// GET /api/projects - get all projects for the current user
+export const GET = withAuth(async ({ session }) => {
+ const projects = await prisma.project.findMany({
+ where: {
+ users: {
+ some: {
+ userId: session.user.id,
+ },
+ },
+ },
+ });
+ return NextResponse.json(projects);
+});
+
export const POST = withAuth(async ({ req, session }) => {
const { name, slug, domain } = await req.json();
if (!name || !slug || !domain) {
diff --git a/apps/web/app/api/route.ts b/apps/web/app/api/route.ts
index 3afc01db60..ef0d56e695 100644
--- a/apps/web/app/api/route.ts
+++ b/apps/web/app/api/route.ts
@@ -163,12 +163,12 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
{
name: "slug",
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to create links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
in: "path",
required: true,
schema: {
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project to create links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
type: "string",
},
},
@@ -214,12 +214,12 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
{
name: "slug",
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
in: "path",
required: true,
schema: {
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
type: "string",
},
},
@@ -276,12 +276,12 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
{
name: "slug",
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
in: "path",
required: true,
schema: {
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
type: "string",
},
},
@@ -335,12 +335,12 @@ export function GET(): NextResponse<OpenAPIV3.Document> {
{
name: "slug",
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
in: "path",
required: true,
schema: {
description:
- "The slug for the project to retrieve links for. E.g. for app.dub.co/acme, the slug is 'acme'.",
+ "The slug for the project that the link belongs to. E.g. for app.dub.co/acme, the slug is 'acme'.",
type: "string",
},
},