fix: made project list authenticated (#428)

This commit is contained in:
Dakshesh Jain 2023-03-14 12:21:06 +05:30 committed by GitHub
parent 0ba81a10f1
commit 0117ccfca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;