mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-28 21:57:23 +02:00
🔓 Add config to secure instance from unauth users (#559)
This commit is contained in:
parent
e65c87bf04
commit
1b38a3cf76
16 changed files with 194 additions and 104 deletions
|
@ -101,6 +101,34 @@ export const composeGetServerSideProps = (
|
|||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Require user to be logged in
|
||||
* @returns
|
||||
*/
|
||||
export const withAuth: GetServerSideProps = async (ctx) => {
|
||||
if (!ctx.req.session.user || ctx.req.session.user.isGuest) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/login",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return { props: {} };
|
||||
};
|
||||
|
||||
/**
|
||||
* Require user to be logged in if AUTH_REQUIRED is true
|
||||
* @returns
|
||||
*/
|
||||
export const withAuthIfRequired: GetServerSideProps = async (ctx) => {
|
||||
if (process.env.AUTH_REQUIRED === "true") {
|
||||
return await withAuth(ctx);
|
||||
}
|
||||
return { props: {} };
|
||||
};
|
||||
|
||||
export function withSessionSsr(
|
||||
handler: GetServerSideProps | GetServerSideProps[],
|
||||
options?: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue