The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added minimal RBAC, removed unnecessary pr-10s
Steven Tey98ffb39aba1b
diff --git a/app/protected/[domain]/[key]/form.tsx b/app/protected/[domain]/[key]/form.tsxindex 21903222a4..a69c71ed02 100644--- a/app/protected/[domain]/[key]/form.tsx+++ b/app/protected/[domain]/[key]/form.tsx@@ -49,9 +49,9 @@ export default function PasswordForm() {}}className={`${error- ? "border-red-300 text-red-500 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ ? "border-red-300 pr-10 text-red-500 placeholder-red-300 focus:border-red-500 focus:ring-red-500": "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"- } block w-full rounded-md pr-10 focus:outline-none sm:text-sm`}+ } block w-full rounded-md focus:outline-none sm:text-sm`}/>{error && (<div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">diff --git a/app/ui/modals/add-edit-link-modal/index.tsx b/app/ui/modals/add-edit-link-modal/index.tsxindex 9ea450b968..bdaad2b019 100644--- a/app/ui/modals/add-edit-link-modal/index.tsx+++ b/app/ui/modals/add-edit-link-modal/index.tsx@@ -473,9 +473,9 @@ function AddEditLinkModal({pattern="[\p{Letter}\p{Mark}\d-]+" // Unicode regex to match characters from all languages and numbers (and omit all symbols except for dashes)className={`${keyError- ? "border-red-300 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500": "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"- } block w-full rounded-r-md pr-10 focus:outline-none sm:text-sm`}+ } block w-full rounded-r-md focus:outline-none sm:text-sm`}placeholder="github"value={key}onChange={(e) => {diff --git a/app/ui/modals/add-edit-link-modal/og-section.tsx b/app/ui/modals/add-edit-link-modal/og-section.tsxindex b350c7d73c..be91b26bba 100644--- a/app/ui/modals/add-edit-link-modal/og-section.tsx+++ b/app/ui/modals/add-edit-link-modal/og-section.tsx@@ -257,7 +257,7 @@ export default function OGSection({id={`title-${randomIdx}`}minRows={3}maxLength={120}- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"placeholder="Dub - Open Source Bitly Alternative"value={title || ""}onChange={(e) => {@@ -288,7 +288,7 @@ export default function OGSection({id={`description-${randomIdx}`}minRows={3}maxLength={240}- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"placeholder="Dub is open-source link management tool for modern marketing teams to create, share, and track short links."value={description || ""}onChange={(e) => {diff --git a/components/app/modals/add-edit-link-modal/og-section.tsx b/components/app/modals/add-edit-link-modal/og-section.tsxindex 2cff97c7ac..37be7b2fc0 100644--- a/components/app/modals/add-edit-link-modal/og-section.tsx+++ b/components/app/modals/add-edit-link-modal/og-section.tsx@@ -255,7 +255,7 @@ export default function OGSection({id="title"minRows={3}maxLength={120}- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"placeholder="Dub - Open Source Bitly Alternative"value={title || ""}onChange={(e) => {@@ -286,7 +286,7 @@ export default function OGSection({id="description"minRows={3}maxLength={240}- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"placeholder="Dub is open-source link management tool for modern marketing teams to create, share, and track short links."value={description || ""}onChange={(e) => {diff --git a/components/app/modals/add-project-modal.tsx b/components/app/modals/add-project-modal.tsxindex fb7a500a60..7e5f75e6b4 100644--- a/components/app/modals/add-project-modal.tsx+++ b/components/app/modals/add-project-modal.tsx@@ -243,9 +243,9 @@ function AddProjectModalHelper({pattern="[a-zA-Z0-9\-.]+"className={`${domainError- ? "border-red-300 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500": "border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:ring-gray-500"- } block w-full rounded-md pr-10 focus:outline-none sm:text-sm`}+ } block w-full rounded-md focus:outline-none sm:text-sm`}placeholder="dub.sh"value={domain}onChange={(e) => {diff --git a/components/app/modals/delete-account-modal.tsx b/components/app/modals/delete-account-modal.tsxindex d23995b694..89b45ea662 100644--- a/components/app/modals/delete-account-modal.tsx+++ b/components/app/modals/delete-account-modal.tsx@@ -99,7 +99,7 @@ function DeleteAccountModal({requiredautoFocus={false}autoComplete="off"- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"/></div></div>diff --git a/components/app/modals/delete-link-modal.tsx b/components/app/modals/delete-link-modal.tsxindex 9284d8d9c1..37c1d066fb 100644--- a/components/app/modals/delete-link-modal.tsx+++ b/components/app/modals/delete-link-modal.tsx@@ -108,7 +108,7 @@ function DeleteLinkModal({requiredautoFocusautoComplete="off"- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"/></div></div>diff --git a/components/app/modals/delete-project-modal.tsx b/components/app/modals/delete-project-modal.tsxindex 614bb374f0..45fca55fd9 100644--- a/components/app/modals/delete-project-modal.tsx+++ b/components/app/modals/delete-project-modal.tsx@@ -12,6 +12,7 @@ import BlurImage from "#/ui/blur-image";import Modal from "#/ui/modal";import useProject from "#/lib/swr/use-project";import Button from "#/ui/button";+import { cn } from "#/lib/utils";function DeleteProjectModal({showDeleteProjectModal,@@ -22,28 +23,36 @@ function DeleteProjectModal({}) {const router = useRouter();const { slug } = router.query as { slug: string };- const { id, logo } = useProject();+ const { id, logo, isOwner } = useProject();++ console.log({ isOwner });const [deleting, setDeleting] = useState(false);async function deleteProject() {- setDeleting(true);- await fetch(`/api/projects/${slug}`, {- method: "DELETE",- headers: {- "Content-Type": "application/json",- },- }).catch((err) => {- setDeleting(false);- throw new Error(err);+ return new Promise((resolve, reject) => {+ setDeleting(true);+ fetch(`/api/projects/${slug}`, {+ method: "DELETE",+ headers: {+ "Content-Type": "application/json",+ },+ }).then(async (res) => {+ setDeleting(false);+ if (res.ok) {+ router.push("/");+ mutate("/api/projects");+ // delay to allow for the route change to complete+ await new Promise(() =>+ setTimeout(() => {+ resolve(null);+ }, 200),+ );+ } else {+ const error = await res.text();+ reject(error);+ }+ });});- router.push("/");- mutate("/api/projects");- // delay to allow for the route change to complete- await new Promise((resolve) =>- setTimeout(() => {- resolve(null);- }, 200),- );}return (@@ -94,7 +103,13 @@ function DeleteProjectModal({autoFocus={false}autoComplete="off"pattern={slug}- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ disabled={!isOwner}+ className={cn(+ "block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm",+ {+ "cursor-not-allowed bg-gray-100": !isOwner,+ },+ )}/></div></div>@@ -116,7 +131,13 @@ function DeleteProjectModal({requiredautoFocus={false}autoComplete="off"- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ disabled={!isOwner}+ className={cn(+ "block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm",+ {+ "cursor-not-allowed bg-gray-100": !isOwner,+ },+ )}/></div></div>@@ -125,6 +146,9 @@ function DeleteProjectModal({text="Confirm delete project"variant="danger"loading={deleting}+ {...(!isOwner && {+ disabledTooltip: "Only project owners can delete a project.",+ })}/></form></Modal>diff --git a/components/app/modals/invite-teammate-modal.tsx b/components/app/modals/invite-teammate-modal.tsxindex 7a4eb0dbae..434c9ea7bd 100644--- a/components/app/modals/invite-teammate-modal.tsx+++ b/components/app/modals/invite-teammate-modal.tsx@@ -91,7 +91,7 @@ function InviteTeammateModal({requiredvalue={email}onChange={(e) => setEmail(e.target.value)}- className="block w-full rounded-md border-gray-300 pr-10 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"/></div></div>diff --git a/components/app/projects/delete-project.tsx b/components/app/projects/delete-project.tsxindex be4ca2d2f3..83945b8f49 100644--- a/components/app/projects/delete-project.tsx+++ b/components/app/projects/delete-project.tsx@@ -1,11 +1,19 @@+import useProject from "#/lib/swr/use-project";+import { cn } from "#/lib/utils";import Button from "#/ui/button";import { useDeleteProjectModal } from "components/app/modals/delete-project-modal";export default function DeleteProject() {const { setShowDeleteProjectModal, DeleteProjectModal } =useDeleteProjectModal();++ const { isOwner } = useProject();return (- <div className="rounded-lg border border-red-600 bg-white">+ <div+ className={cn("rounded-lg border border-red-600 bg-white", {+ "border-gray-200": !isOwner,+ })}+ ><DeleteProjectModal /><div className="flex flex-col space-y-3 p-5 sm:p-10"><h2 className="text-xl font-medium">Delete Project</h2>@@ -15,7 +23,11 @@ export default function DeleteProject() {with caution.</p></div>- <div className="border-b border-red-600" />+ <div+ className={cn("border-b border-red-600", {+ "border-gray-200": !isOwner,+ })}+ /><div className="flex items-center justify-end px-5 py-4 sm:px-10"><div>@@ -23,6 +35,9 @@ export default function DeleteProject() {text="Delete Project"variant="danger"onClick={() => setShowDeleteProjectModal(true)}+ {...(!isOwner && {+ disabledTooltip: "Only project owners can delete a project.",+ })}/></div></div>diff --git a/lib/auth.ts b/lib/auth.tsindex 8a536af99a..26b6e65ec0 100644--- a/lib/auth.ts+++ b/lib/auth.ts@@ -38,10 +38,12 @@ const withProjectAuth ={excludeGet, // if the action doesn't need to be gated for GET requestsrequiredPlan = ["free", "pro", "enterprise"], // if the action needs a specific plan+ requiredRole = ["owner", "member"],needNotExceededUsage, // if the action needs the user to not have exceeded their usage}: {excludeGet?: boolean;requiredPlan?: Array<PlanProps>;+ requiredRole?: Array<"owner" | "member">;needNotExceededUsage?: boolean;} = {},) =>@@ -81,9 +83,9 @@ const withProjectAuth =},})) as ProjectProps;- if (project) {+ if (project && project.users) {// project exists but user is not part of it- if (project.users && project.users.length === 0) {+ if (project.users.length === 0) {const pendingInvites = await prisma.projectInvite.findUnique({where: {email_projectId: {@@ -109,8 +111,13 @@ const withProjectAuth =}// if the action doesn't need to be gated for GET requests, return handler now- if (req.method === "GET" && excludeGet)+ if (req.method === "GET" && excludeGet) {return handler(req, res, project, session);+ }++ if (!requiredRole.includes(project.users[0].role)) {+ return res.status(403).end("Unauthorized: Insufficient permissions.");+ }if (needNotExceededUsage && project.usage > project.usageLimit) {return res.status(403).end("Unauthorized: Usage limits exceeded.");diff --git a/lib/swr/use-project.ts b/lib/swr/use-project.tsindex 170f86dfad..82cc34170b 100644--- a/lib/swr/use-project.ts+++ b/lib/swr/use-project.ts@@ -27,6 +27,7 @@ export default function useProject() {return {...project,+ isOwner: project?.users && project.users[0].role === "owner",exceededUsage,error,loading: !router.isReady || (slug && !project && !error),diff --git a/pages/api/projects/[slug]/domains/[domain]/index.ts b/pages/api/projects/[slug]/domains/[domain]/index.tsindex 4194e5d2c9..430261f4eb 100644--- a/pages/api/projects/[slug]/domains/[domain]/index.ts+++ b/pages/api/projects/[slug]/domains/[domain]/index.ts@@ -13,65 +13,66 @@ import {} from "#/lib/api/domains";import { redis } from "#/lib/upstash";-export default withProjectAuth(async (req, res, project) => {- const { slug, domain } = req.query as { slug: string; domain: string };+export default withProjectAuth(+ async (req, res, project) => {+ const { slug, domain } = req.query as { slug: string; domain: string };- if (- !slug ||- typeof slug !== "string" ||- !domain ||- typeof domain !== "string"- ) {- return res- .status(400)- .end("Missing or misconfigured project slug or domain");- }-- // prevent unauthorized access to domains that don't belong to the project- const domainBelongsToProject = await prisma.domain.findFirst({- where: {- slug: domain,- projectId: project.id,- },- });- if (!domainBelongsToProject) {- return res.status(404).end("Domain not found");- }-- // PUT /api/projects/[slug]/domains/[domain] edit a project's domain- if (req.method === "PUT") {- const { slug: newDomain, target, type, primary } = req.body;+ if (+ !slug ||+ typeof slug !== "string" ||+ !domain ||+ typeof domain !== "string"+ ) {+ return res+ .status(400)+ .end("Missing or misconfigured project slug or domain");+ }- const validDomain = await validateDomain(newDomain, project.id);- if (validDomain !== true) {- return res.status(422).json({- domainError: validDomain,- });+ // prevent unauthorized access to domains that don't belong to the project+ const domainBelongsToProject = await prisma.domain.findFirst({+ where: {+ slug: domain,+ projectId: project.id,+ },+ });+ if (!domainBelongsToProject) {+ return res.status(404).end("Domain not found");}- if (newDomain !== domain) {- const vercelResponse = await addDomainToVercel(newDomain);- if (vercelResponse.error) {+ // PUT /api/projects/[slug]/domains/[domain] edit a project's domain+ if (req.method === "PUT") {+ const { slug: newDomain, target, type, primary } = req.body;++ const validDomain = await validateDomain(newDomain, project.id);+ if (validDomain !== true) {return res.status(422).json({- domainError: vercelResponse.error.message,+ domainError: validDomain,});}- }- const response = await Promise.allSettled([- // if the domain is being changed, we need to:- // 1. Remove the old domain from Vercel- // 2. Add the new domain to Vercel- // 3. Update all links in the project to point to the new domain- // 4. Update all images in the project to point to the new domain- ...(newDomain !== domain- ? [- removeDomainFromVercel(domain),- changeDomainForLinks(domain, newDomain),- changeDomainForImages(domain, newDomain),- ]- : []),- /*+ if (newDomain !== domain) {+ const vercelResponse = await addDomainToVercel(newDomain);+ if (vercelResponse.error) {+ return res.status(422).json({+ domainError: vercelResponse.error.message,+ });+ }+ }++ const response = await Promise.allSettled([+ // if the domain is being changed, we need to:+ // 1. Remove the old domain from Vercel+ // 2. Add the new domain to Vercel+ // 3. Update all links in the project to point to the new domain+ // 4. Update all images in the project to point to the new domain+ ...(newDomain !== domain+ ? [+ removeDomainFromVercel(domain),+ changeDomainForLinks(domain, newDomain),+ changeDomainForImages(domain, newDomain),+ ]+ : []),+ /*if the project is not a free plan:- if the domain is being set:- Set the root domain to the target in Redis@@ -79,58 +80,62 @@ export default withProjectAuth(async (req, res, project) => {- if the domain is being unset:- delete the root domain key in Redis*/- project.plan !== "free" &&- (target- ? setRootDomain(- domain,- target,- type === "rewrite",- newDomain !== domain && newDomain,- )- : redis.del(`root:${domain}`)),- // if the domain is being set as the primary domain, set the current primary domain to false- primary &&- prisma.domain.updateMany({+ project.plan !== "free" &&+ (target+ ? setRootDomain(+ domain,+ target,+ type === "rewrite",+ newDomain !== domain && newDomain,+ )+ : redis.del(`root:${domain}`)),+ // if the domain is being set as the primary domain, set the current primary domain to false+ primary &&+ prisma.domain.updateMany({+ where: {+ projectId: project.id,+ primary: true,+ },+ data: {+ primary: false,+ },+ }),+ // Update the domain in the database along with its primary status+ prisma.domain.update({where: {- projectId: project.id,- primary: true,+ slug: domain,},data: {- primary: false,+ ...(newDomain !== domain && {+ slug: newDomain,+ }),+ // same logic as the redis part above+ ...(project.plan !== "free" &&+ (target+ ? {+ target,+ }+ : {+ target: null,+ })),+ type,+ primary,},}),- // Update the domain in the database along with its primary status- prisma.domain.update({- where: {- slug: domain,- },- data: {- ...(newDomain !== domain && {- slug: newDomain,- }),- // same logic as the redis part above- ...(project.plan !== "free" &&- (target- ? {- target,- }- : {- target: null,- })),- type,- primary,- },- }),- ]);+ ]);- return res.status(200).json(response);+ return res.status(200).json(response);- // DELETE /api/projects/[slug]/domains/[domain] delete a project's domain- } else if (req.method === "DELETE") {- const response = await deleteDomainAndLinks(domain);- return res.status(200).json(response);- } else {- res.setHeader("Allow", ["PUT", "DELETE"]);- return res.status(405).end(`Method ${req.method} Not Allowed`);- }-});+ // DELETE /api/projects/[slug]/domains/[domain] delete a project's domain+ } else if (req.method === "DELETE") {+ const response = await deleteDomainAndLinks(domain);+ return res.status(200).json(response);+ } else {+ res.setHeader("Allow", ["PUT", "DELETE"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+ },+ {+ requiredRole: ["owner"],+ },+);diff --git a/pages/api/projects/[slug]/index.ts b/pages/api/projects/[slug]/index.tsindex 2d4ef57e50..c00dc85286 100644--- a/pages/api/projects/[slug]/index.ts+++ b/pages/api/projects/[slug]/index.ts@@ -4,75 +4,81 @@ import prisma from "#/lib/prisma";import { cancelSubscription } from "#/lib/stripe";import cloudinary from "cloudinary";-export default withProjectAuth(async (req, res, project) => {- // GET /api/projects/[slug] – get a specific project- if (req.method === "GET") {- return res.status(200).json(project);+export default withProjectAuth(+ async (req, res, project, session) => {+ // GET /api/projects/[slug] – get a specific project+ if (req.method === "GET") {+ return res.status(200).json(project);- // PUT /api/projects/[slug] – edit a specific project- } else if (req.method === "PUT") {- const { name, slug } = req.body;- try {- const response = await prisma.project.update({- where: {- slug: project.slug,- },- data: {- ...(name && { name }),- ...(slug && { slug }),- },- });- return res.status(200).json(response);- } catch (error) {- if (error.code === "P2002") {- return res.status(422).end("Project slug already exists.");+ // PUT /api/projects/[slug] – edit a specific project+ } else if (req.method === "PUT") {+ const { name, slug } = req.body;+ try {+ const response = await prisma.project.update({+ where: {+ slug: project.slug,+ },+ data: {+ ...(name && { name }),+ ...(slug && { slug }),+ },+ });+ return res.status(200).json(response);+ } catch (error) {+ if (error.code === "P2002") {+ return res.status(422).end("Project slug already exists.");+ }}- }- // DELETE /api/projects/[slug] – delete a project- } else if (req.method === "DELETE") {- const domains = (- await prisma.domain.findMany({- where: {- projectId: project.id,- },- select: {- slug: true,- },- })- ).map((domain) => domain.slug);+ // DELETE /api/projects/[slug] – delete a project+ } else if (req.method === "DELETE") {+ const domains = (+ await prisma.domain.findMany({+ where: {+ projectId: project.id,+ },+ select: {+ slug: true,+ },+ })+ ).map((domain) => domain.slug);- // delete all domains, links, and uploaded images associated with the project- const deleteDomainsResponse = await Promise.allSettled(- domains.map((domain) =>- deleteDomainAndLinks(domain, {- // here, we don't need to delete in prisma because we're deleting the project later and have onDelete: CASCADE set- skipPrismaDelete: true,- }),- ),- );+ // delete all domains, links, and uploaded images associated with the project+ const deleteDomainsResponse = await Promise.allSettled(+ domains.map((domain) =>+ deleteDomainAndLinks(domain, {+ // here, we don't need to delete in prisma because we're deleting the project later and have onDelete: CASCADE set+ skipPrismaDelete: true,+ }),+ ),+ );- const deleteProjectResponse = await Promise.all([- // delete project logo from Cloudinary- project.logo &&- cloudinary.v2.uploader.destroy(`logos/${project.id}`, {- invalidate: true,+ const deleteProjectResponse = await Promise.all([+ // delete project logo from Cloudinary+ project.logo &&+ cloudinary.v2.uploader.destroy(`logos/${project.id}`, {+ invalidate: true,+ }),+ // if they have a Stripe subscription, cancel it+ project.stripeId && cancelSubscription(project.stripeId),+ // delete the project+ prisma.project.delete({+ where: {+ slug: project.slug,+ },}),- // if they have a Stripe subscription, cancel it- project.stripeId && cancelSubscription(project.stripeId),- // delete the project- prisma.project.delete({- where: {- slug: project.slug,- },- }),- ]);+ ]);- return res.status(200).json({- deleteProjectResponse,- deleteDomainsResponse,- });- } else {- res.setHeader("Allow", ["GET", "PUT", "DELETE"]);- return res.status(405).end(`Method ${req.method} Not Allowed`);- }-});+ return res.status(200).json({+ deleteProjectResponse,+ deleteDomainsResponse,+ });+ } else {+ res.setHeader("Allow", ["GET", "PUT", "DELETE"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+ },+ {+ requiredRole: ["owner"],+ excludeGet: true,+ },+);diff --git a/pages/api/projects/[slug]/logo.ts b/pages/api/projects/[slug]/logo.tsindex dfe5945de2..a9362efd9e 100644--- a/pages/api/projects/[slug]/logo.ts+++ b/pages/api/projects/[slug]/logo.ts@@ -10,26 +10,32 @@ export const config = {},};-export default withProjectAuth(async (req, res, project) => {- // POST /api/projects/[slug]/logo – upload a new logo- if (req.method === "POST") {- const { image } = req.body;+export default withProjectAuth(+ async (req, res, project) => {+ // POST /api/projects/[slug]/logo – upload a new logo+ if (req.method === "POST") {+ const { image } = req.body;- const { secure_url } = await cloudinary.v2.uploader.upload(image, {- public_id: project.id,- folder: "logos",- overwrite: true,- invalidate: true,- });+ const { secure_url } = await cloudinary.v2.uploader.upload(image, {+ public_id: project.id,+ folder: "logos",+ overwrite: true,+ invalidate: true,+ });- const response = await prisma.project.update({- where: { id: project.id },- data: { logo: secure_url },- });+ const response = await prisma.project.update({+ where: { id: project.id },+ data: { logo: secure_url },+ });- return res.status(200).json(response);- } else {- res.setHeader("Allow", ["POST"]);- return res.status(405).end(`Method ${req.method} Not Allowed`);- }-});+ return res.status(200).json(response);+ } else {+ res.setHeader("Allow", ["POST"]);+ return res.status(405).end(`Method ${req.method} Not Allowed`);+ }+ },+ {+ requiredRole: ["owner"],+ excludeGet: true,+ },+);diff --git a/pages/api/projects/[slug]/saml.ts b/pages/api/projects/[slug]/saml.tsindex 8f2156cb41..9b9399ad8f 100644--- a/pages/api/projects/[slug]/saml.ts+++ b/pages/api/projects/[slug]/saml.ts@@ -1,6 +1,5 @@import { withProjectAuth } from "#/lib/auth";import jackson, { samlAudience, samlPath } from "#/lib/jackson";-import prisma from "#/lib/prisma";export default withProjectAuth(async (req, res, project) => {@@ -19,8 +18,6 @@ export default withProjectAuth(acs: `${process.env.NEXTAUTH_URL}${samlPath}`,};- console.log(JSON.stringify(response, null, 2));-return res.status(200).json(response);// POST /api/projects/[slug]/saml – create a new SAML connection@@ -61,6 +58,7 @@ export default withProjectAuth(}},{+ requiredRole: ["owner"],requiredPlan: ["enterprise"],excludeGet: true,},diff --git a/pages/api/projects/[slug]/scim.ts b/pages/api/projects/[slug]/scim.tsindex ff166d263a..ea237d6234 100644--- a/pages/api/projects/[slug]/scim.ts+++ b/pages/api/projects/[slug]/scim.ts@@ -68,6 +68,7 @@ export default withProjectAuth(}},{+ requiredRole: ["owner"],requiredPlan: ["enterprise"],excludeGet: true,},