add validation for update organization

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-28 23:24:22 +02:00
parent aa5c881ec6
commit 48becb23dc
4 changed files with 43 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ import {
type GetServerSidePropsResult,
} from "next";
import { getServerAuthSession } from "./auth";
import { db } from "./db";
export function createServerSideProps(
cb?: (context: GetServerSidePropsContext) => Promise<any>,
@@ -10,7 +11,7 @@ export function createServerSideProps(
return async function getServerSideProps(
context: GetServerSidePropsContext,
): Promise<GetServerSidePropsResult<any>> {
const session = await getServerAuthSession(context);
const session = await getServerAuthSession(context);
if(!session) {
return {
@@ -21,6 +22,23 @@ export function createServerSideProps(
}
}
if(context.params?.organization) {
const organization = await db.user.findFirst({
where: {
id: session.user.id,
organization: {
slug: context.params.organization as string
}
}
})
if(!organization) {
return {
notFound: true,
}
}
}
const res = await (typeof cb === "function"
? cb(context)
: Promise.resolve({}));