Fixing permission for admin wizard (#6061)

* Fixing permission

* Update apps/web/pages/auth/setup/index.tsx

* Correcting error page code

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
pull/6109/head^2
Leo Giovanetti 2022-12-19 11:50:25 -03:00 committed by GitHub
parent 6be0fd52e7
commit 11a07961d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,9 @@
import { UserPermissionRole } from "@prisma/client";
import { GetServerSidePropsContext } from "next";
import { useState } from "react";
import AdminAppsList from "@calcom/features/apps/AdminAppsList";
import { getSession } from "@calcom/lib/auth";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import prisma from "@calcom/prisma";
import { inferSSRProps } from "@calcom/types/inferSSRProps";
@ -38,8 +41,20 @@ export default function Setup(props: inferSSRProps<typeof getServerSideProps>) {
);
}
export const getServerSideProps = async () => {
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const userCount = await prisma.user.count();
const { req } = context;
const session = await getSession({ req });
if (session?.user.role && session?.user.role !== UserPermissionRole.ADMIN) {
return {
redirect: {
destination: `/404`,
permanent: false,
},
};
}
return {
props: {
userCount,