Skip to content

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

feat: redirect if user not logged in

Marc Seitz932a2cdd7bc7
diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsx
index bc01251f..c6b5bc8c 100644
--- a/pages/view/[linkId]/chat.tsx
+++ b/pages/view/[linkId]/chat.tsx
@@ -22,6 +22,16 @@ const roleToNameMap: Record<Message["role"], string> = {
export const getServerSideProps = async (context: any) => {
const { linkId } = context.params;
const session = await getServerSession(context.req, context.res, authOptions);
+
+ if (!session) {
+ return {
+ redirect: {
+ permanent: false,
+ destination: `/login?next=/view/${linkId}/chat`,
+ },
+ };
+ }
+
const document = await prisma.link.findUnique({
where: { id: linkId },
select: {
@@ -43,7 +53,7 @@ export const getServerSideProps = async (context: any) => {
},
body: JSON.stringify({
documentId: document!.document.id,
- userId: (session!.user as CustomUser).id,
+ userId: (session.user as CustomUser).id,
}),
},
);