1
0
Fork 0

refactor(pages): require authentication to visit pages

This commit is contained in:
Vojtěch Mareš 2023-06-26 23:10:17 +02:00
parent 019267584a
commit 5a300f9f88
Signed by: vojtech.mares
GPG key ID: C6827B976F17240D
3 changed files with 24 additions and 5 deletions

View file

@ -4,12 +4,17 @@ import Link from "next/link";
import { formatCurrency } from "~/lib/currency/formatter";
import { getServerAuthSession } from "~/server/auth";
import { prisma } from "~/server/db";
import { Training } from "lib/content/training";
import { Layout } from "~/components/Layout";
import { Button } from "~/components/Button";
export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const session = await getServerAuthSession(ctx);
if (!session) return { redirect: { destination: '/api/auth/signin', permanent: false } };
const trainings = await prisma.training.findMany({
select: {
id: true,
@ -21,7 +26,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res }) => {
priceCorporate: true,
}
});
return { props: { trainings: trainings } };
return { props: { trainings: trainings, session } };
}
function Table({trainings}: { trainings: Training[] }) {