From 0117ccfca2216682b466fa4a9775ae7211229257 Mon Sep 17 00:00:00 2001 From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Date: Tue, 14 Mar 2023 12:21:06 +0530 Subject: [PATCH] fix: made project list authenticated (#428) --- .../pages/[workspaceSlug]/projects/index.tsx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/app/pages/[workspaceSlug]/projects/index.tsx b/apps/app/pages/[workspaceSlug]/projects/index.tsx index e877546c9..e0b7c9d45 100644 --- a/apps/app/pages/[workspaceSlug]/projects/index.tsx +++ b/apps/app/pages/[workspaceSlug]/projects/index.tsx @@ -1,6 +1,8 @@ import React, { useState } from "react"; import { useRouter } from "next/router"; import { mutate } from "swr"; +// lib +import { requiredAuth } from "lib/auth"; // services import projectService from "services/project.service"; // hooks @@ -17,7 +19,7 @@ import { Breadcrumbs, BreadcrumbItem } from "components/breadcrumbs"; // icons import { ClipboardDocumentListIcon, PlusIcon } from "@heroicons/react/24/outline"; // types -import type { NextPage } from "next"; +import type { GetServerSidePropsContext, NextPage } from "next"; // fetch-keys import { PROJECT_MEMBERS } from "constants/fetch-keys"; @@ -127,4 +129,25 @@ const ProjectsPage: NextPage = () => { ); }; +export const getServerSideProps = async (ctx: GetServerSidePropsContext) => { + const user = await requiredAuth(ctx.req?.headers.cookie); + + const redirectAfterSignIn = ctx.resolvedUrl; + + if (!user) { + return { + redirect: { + destination: `/signin?next=${redirectAfterSignIn}`, + permanent: false, + }, + }; + } + + return { + props: { + user, + }, + }; +}; + export default ProjectsPage;