web: ssr redirects

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-12-31 13:35:11 +01:00
parent 1ec95ca242
commit 31a4e1a277
4 changed files with 67 additions and 18 deletions

View File

@@ -21,7 +21,7 @@ export function createServerSideProps(
}
if (context.params?.organization) {
const organization = await db.user.findFirst({
const user = await db.user.findFirst({
where: {
id: session.user.id,
organization: {
@@ -30,11 +30,35 @@ export function createServerSideProps(
},
});
if (!organization) {
if (!user) {
return {
notFound: true,
};
}
} else {
const user = await db.user.findFirst({
where: {
id: session.user.id,
},
include: {
organization: true,
},
});
if (!user) {
return {
notFound: true,
};
}
if (user.organization) {
return {
redirect: {
destination: `/${user.organization.slug}`,
permanent: false,
},
};
}
}
const res = await (typeof cb === 'function'