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:
parent
7d70ea7c20
commit
6482e41cd8
2 changed files with 16 additions and 5 deletions
|
@ -79,6 +79,10 @@ export class WhoAmI {
|
||||||
public isTemporary(): boolean {
|
public isTemporary(): boolean {
|
||||||
return this.#me?.temporary ?? false;
|
return this.#me?.temporary ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isEmpty(): boolean {
|
||||||
|
return !this.#me;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type WhoAmIProps = {
|
type WhoAmIProps = {
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { useMatches } from "react-router-dom";
|
||||||
|
|
||||||
import { ForbiddenSection } from "../ForbiddenSection";
|
import { ForbiddenSection } from "../ForbiddenSection";
|
||||||
import { useAccess } from "../context/access/Access";
|
import { useAccess } from "../context/access/Access";
|
||||||
|
import { useWhoAmI } from "../context/whoami/WhoAmI";
|
||||||
|
import { KeycloakSpinner } from "@keycloak/keycloak-ui-shared";
|
||||||
|
|
||||||
function hasProp<K extends PropertyKey>(
|
function hasProp<K extends PropertyKey>(
|
||||||
data: object,
|
data: object,
|
||||||
|
@ -14,6 +16,7 @@ function hasProp<K extends PropertyKey>(
|
||||||
export const AuthWall = ({ children }: any) => {
|
export const AuthWall = ({ children }: any) => {
|
||||||
const matches = useMatches();
|
const matches = useMatches();
|
||||||
const { hasAccess } = useAccess();
|
const { hasAccess } = useAccess();
|
||||||
|
const { whoAmI } = useWhoAmI();
|
||||||
|
|
||||||
const permissionNeeded = matches.flatMap(({ handle }) => {
|
const permissionNeeded = matches.flatMap(({ handle }) => {
|
||||||
if (
|
if (
|
||||||
|
@ -31,9 +34,13 @@ export const AuthWall = ({ children }: any) => {
|
||||||
return [handle.access] as AccessType[];
|
return [handle.access] as AccessType[];
|
||||||
});
|
});
|
||||||
|
|
||||||
return hasAccess(...permissionNeeded) ? (
|
if (whoAmI.isEmpty()) {
|
||||||
children
|
return <KeycloakSpinner />;
|
||||||
) : (
|
}
|
||||||
<ForbiddenSection permissionNeeded={permissionNeeded} />
|
|
||||||
);
|
if (!hasAccess(...permissionNeeded)) {
|
||||||
|
return <ForbiddenSection permissionNeeded={permissionNeeded} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return children;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue