mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-14 17:26:26 +01:00
🐛 Access callback conditions (#1536)
This commit is contained in:
@@ -62,7 +62,7 @@ export const getServerSideProps: GetServerSideProps<BoardGetServerSideProps> = a
|
|||||||
const result = checkForSessionOrAskForLogin(
|
const result = checkForSessionOrAskForLogin(
|
||||||
ctx,
|
ctx,
|
||||||
session,
|
session,
|
||||||
() => config.settings.access.allowGuests || !!session?.user
|
() => config.settings.access.allowGuests || session?.user != undefined
|
||||||
);
|
);
|
||||||
if (result) {
|
if (result) {
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -14,17 +14,10 @@ export const checkForSessionOrAskForLogin = (
|
|||||||
session: Session | null,
|
session: Session | null,
|
||||||
accessCallback: () => boolean
|
accessCallback: () => boolean
|
||||||
): GetServerSidePropsResult<any> | undefined => {
|
): GetServerSidePropsResult<any> | undefined => {
|
||||||
if (!session?.user) {
|
const permitted = accessCallback();
|
||||||
return {
|
|
||||||
props: {},
|
|
||||||
redirect: {
|
|
||||||
destination: `/auth/login?redirectAfterLogin=${context.resolvedUrl}`,
|
|
||||||
permanent: false,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!accessCallback()) {
|
// user is logged in but does not have the required access
|
||||||
|
if (session?.user && !permitted) {
|
||||||
return {
|
return {
|
||||||
props: {},
|
props: {},
|
||||||
redirect: {
|
redirect: {
|
||||||
@@ -34,5 +27,17 @@ export const checkForSessionOrAskForLogin = (
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
// user *may* be logged in and permitted
|
||||||
|
if (permitted) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// user is logged out and needs to sign in
|
||||||
|
return {
|
||||||
|
props: {},
|
||||||
|
redirect: {
|
||||||
|
destination: `/auth/login?redirectAfterLogin=${context.resolvedUrl}`,
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user