mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 18:52:06 +00:00
25 lines
574 B
TypeScript
25 lines
574 B
TypeScript
import { GetServerSideProps, GetServerSidePropsContext } from 'next';
|
|
import { getLoginSession } from './session';
|
|
|
|
const withPageAuthRequired =
|
|
(fn?: GetServerSideProps) => async (context: GetServerSidePropsContext) => {
|
|
try {
|
|
const { req } = context;
|
|
await getLoginSession(req);
|
|
|
|
if (!fn) {
|
|
return { props: {} };
|
|
}
|
|
return await fn(context);
|
|
} catch (error) {
|
|
return {
|
|
redirect: {
|
|
destination: '/login',
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
};
|
|
|
|
export default withPageAuthRequired;
|