Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: added validation to check Notion page visibility
Ashraf97d27c4403df
diff --git a/components/documents/add-document-modal.tsx b/components/documents/add-document-modal.tsxindex ec46b7a7..70f74756 100644--- a/components/documents/add-document-modal.tsx+++ b/components/documents/add-document-modal.tsx@@ -236,7 +236,9 @@ export function AddDocumentModal({}} catch (error) {setUploading(false);- toast.error("An error occurred while processing the Notion link.");+ toast.error(+ "Oops! Can't access the Notion page. Please double-check it's set to 'Public'.",+ );console.error("An error occurred while processing the Notion link: ",error,diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.tsindex 5cc4b146..a48e7cee 100644--- a/pages/api/teams/[teamId]/documents/index.ts+++ b/pages/api/teams/[teamId]/documents/index.ts@@ -8,6 +8,8 @@ import { identifyUser, trackAnalytics } from "@/lib/analytics";import { getTeamWithUsersAndDocument } from "@/lib/team/helper";import { errorhandler } from "@/lib/errorHandler";import { client } from "@/trigger";+import notion from "@/lib/notion";+import { parsePageId } from "notion-utils";export default async function handle(req: NextApiRequest,@@ -84,7 +86,14 @@ export default async function handle(// Get passed type property or alternatively, the file extension and save it as the typeconst type = fileType || getExtension(name);- // You could perform some validation here+ // Check whether the Notion page is publically accessible or not+ try {+ const pageId = parsePageId(fileUrl, { uuid: false });+ // if the page isn't accessible then end the process here.+ await notion.getPage(pageId);+ } catch (error) {+ return res.status(404).end("This Notion page isn't publically available.");+ }// Save data to the databaseconst document = await prisma.document.create({