Implement authentication using Passport.js

This commit is contained in:
Aaron William Po
2023-02-05 19:27:19 -05:00
parent 86f6f9abc5
commit 087a1a4513
26 changed files with 2073 additions and 412 deletions

View File

@@ -0,0 +1,24 @@
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;