Show forbidden section only after whoAmI is set (#34589)

closes #34402

Signed-off-by: Christian Janker <christian.janker@gmx.at>
This commit is contained in:
Christian Ja 2024-11-05 13:05:02 +01:00 committed by GitHub
parent 7d70ea7c20
commit 6482e41cd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View file

@ -79,6 +79,10 @@ export class WhoAmI {
public isTemporary(): boolean {
return this.#me?.temporary ?? false;
}
public isEmpty(): boolean {
return !this.#me;
}
}
type WhoAmIProps = {

View file

@ -3,6 +3,8 @@ import { useMatches } from "react-router-dom";
import { ForbiddenSection } from "../ForbiddenSection";
import { useAccess } from "../context/access/Access";
import { useWhoAmI } from "../context/whoami/WhoAmI";
import { KeycloakSpinner } from "@keycloak/keycloak-ui-shared";
function hasProp<K extends PropertyKey>(
data: object,
@ -14,6 +16,7 @@ function hasProp<K extends PropertyKey>(
export const AuthWall = ({ children }: any) => {
const matches = useMatches();
const { hasAccess } = useAccess();
const { whoAmI } = useWhoAmI();
const permissionNeeded = matches.flatMap(({ handle }) => {
if (
@ -31,9 +34,13 @@ export const AuthWall = ({ children }: any) => {
return [handle.access] as AccessType[];
});
return hasAccess(...permissionNeeded) ? (
children
) : (
<ForbiddenSection permissionNeeded={permissionNeeded} />
);
if (whoAmI.isEmpty()) {
return <KeycloakSpinner />;
}
if (!hasAccess(...permissionNeeded)) {
return <ForbiddenSection permissionNeeded={permissionNeeded} />;
}
return children;
};