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.

828 B
Raw Blame
import { withSession } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { DEFAULT_REDIRECTS, RESERVED_SLUGS } from "@dub/utils";
import { NextResponse } from "next/server";

// GET /api/misc/check-workspace-slug – check if a workspace slug is available
export const GET = withSession(async ({ searchParams }) => {
  const { slug } = searchParams;

  if (!slug) {
    return NextResponse.json(
      { error: "Slug parameter is required" },
      { status: 400 },
    );
  }

  if (RESERVED_SLUGS.includes(slug) || DEFAULT_REDIRECTS[slug]) {
    return NextResponse.json(1);
  }
  const project = await prisma.project.findUnique({
    where: {
      slug,
    },
    select: {
      slug: true,
    },
  });
  if (project) {
    return NextResponse.json(1);
  } else {
    return NextResponse.json(0);
  }
});