refactor(pages): require authentication to visit pages
This commit is contained in:
parent
019267584a
commit
5a300f9f88
3 changed files with 24 additions and 5 deletions
|
|
@ -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[] }) {
|
||||
|
|
|
|||
Reference in a new issue