added tooling (eslint, typescript and prettier)
This commit is contained in:
@@ -1,45 +1,46 @@
|
||||
import {
|
||||
type GetServerSidePropsContext,
|
||||
type GetServerSidePropsResult,
|
||||
} from "next";
|
||||
import { getServerAuthSession } from "./auth";
|
||||
import { db } from "./db";
|
||||
} from 'next';
|
||||
|
||||
import { getServerAuthSession } from './auth';
|
||||
import { db } from './db';
|
||||
|
||||
export function createServerSideProps(
|
||||
cb?: (context: GetServerSidePropsContext) => Promise<any>,
|
||||
cb?: (context: GetServerSidePropsContext) => Promise<any>
|
||||
) {
|
||||
return async function getServerSideProps(
|
||||
context: GetServerSidePropsContext,
|
||||
context: GetServerSidePropsContext
|
||||
): Promise<GetServerSidePropsResult<any>> {
|
||||
const session = await getServerAuthSession(context);
|
||||
const session = await getServerAuthSession(context);
|
||||
|
||||
if(!session) {
|
||||
if (!session) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/api/auth/signin",
|
||||
destination: '/api/auth/signin',
|
||||
permanent: false,
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if(context.params?.organization) {
|
||||
if (context.params?.organization) {
|
||||
const organization = await db.user.findFirst({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
organization: {
|
||||
slug: context.params.organization as string
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if(!organization) {
|
||||
slug: context.params.organization as string,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!organization) {
|
||||
return {
|
||||
notFound: true,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const res = await (typeof cb === "function"
|
||||
const res = await (typeof cb === 'function'
|
||||
? cb(context)
|
||||
: Promise.resolve({}));
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user