Protect routes and procedures

This commit is contained in:
Manuel
2023-08-05 15:30:59 +02:00
parent 5b1b36eecc
commit cf057505ec
10 changed files with 209 additions and 43 deletions

View File

@@ -10,6 +10,7 @@ import {
IconUser,
IconUserPlus,
} from '@tabler/icons-react';
import { GetServerSideProps } from 'next';
import Head from 'next/head';
import Link from 'next/link';
import { useState } from 'react';
@@ -23,6 +24,8 @@ import {
createAccountSecurityStepValidationSchema,
} from '~/components/Manage/User/Create/security-step';
import { ManageLayout } from '~/components/layout/Templates/ManageLayout';
import { getServerAuthSession } from '~/server/auth';
import { getServerSideTranslations } from '~/tools/server/getServerSideTranslations';
import { api } from '~/utils/api';
const CreateNewUserPage = () => {
@@ -221,4 +224,26 @@ const CreateNewUserPage = () => {
);
};
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const session = await getServerAuthSession(ctx);
if (!session?.user.isAdmin) {
return {
notFound: true,
};
}
const translations = await getServerSideTranslations(
['common'],
ctx.locale,
undefined,
undefined
);
return {
props: {
...translations,
},
};
};
export default CreateNewUserPage;