Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: link-delete-check

Aashish-Upadhyay-101f5178e9529e5
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 4c573236..85725de2 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -2,6 +2,7 @@ import { NextApiRequest, NextApiResponse } from "next";
import prisma from "@/lib/prisma";
import { getServerSession } from "next-auth/next";
import { hashPassword } from "@/lib/utils";
+import { CustomUser } from "@/lib/types";
import { authOptions } from "../../auth/[...nextauth]";
export default async function handle(
@@ -127,6 +128,7 @@ export default async function handle(
return res.status(200).json(updatedLink);
} else if (req.method == "DELETE") {
+ // DELETE /api/links/:id
const session = await getServerSession(req, res, authOptions);
if (!session) {
return res.status(401).end("Unauthorized");
@@ -138,12 +140,23 @@ export default async function handle(
const linkToBeDeleted = await prisma.link.findUnique({
where: {
id: id,
+ },
+ include: {
+ document: {
+ select: {
+ ownerId: true,
+ }
+ }
}
});
if (!linkToBeDeleted) {
return res.status(404).json({ error: "Link not found" });
}
+
+ if (linkToBeDeleted.document.ownerId !== (session.user as CustomUser).id){
+ return res.status(401).end("Unauthorized to access the link");
+ }
await prisma.link.delete({
where: {