From 6482e41cd816e7ea14341fa1df94e599ee0471f7 Mon Sep 17 00:00:00 2001 From: Christian Ja Date: Tue, 5 Nov 2024 13:05:02 +0100 Subject: [PATCH] Show forbidden section only after whoAmI is set (#34589) closes #34402 Signed-off-by: Christian Janker --- js/apps/admin-ui/src/context/whoami/WhoAmI.tsx | 4 ++++ js/apps/admin-ui/src/root/AuthWall.tsx | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/js/apps/admin-ui/src/context/whoami/WhoAmI.tsx b/js/apps/admin-ui/src/context/whoami/WhoAmI.tsx index 2885fdb2a3..f6b287f046 100644 --- a/js/apps/admin-ui/src/context/whoami/WhoAmI.tsx +++ b/js/apps/admin-ui/src/context/whoami/WhoAmI.tsx @@ -79,6 +79,10 @@ export class WhoAmI { public isTemporary(): boolean { return this.#me?.temporary ?? false; } + + public isEmpty(): boolean { + return !this.#me; + } } type WhoAmIProps = { diff --git a/js/apps/admin-ui/src/root/AuthWall.tsx b/js/apps/admin-ui/src/root/AuthWall.tsx index 710ee673db..0d68d68853 100644 --- a/js/apps/admin-ui/src/root/AuthWall.tsx +++ b/js/apps/admin-ui/src/root/AuthWall.tsx @@ -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( data: object, @@ -14,6 +16,7 @@ function hasProp( 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 - ) : ( - - ); + if (whoAmI.isEmpty()) { + return ; + } + + if (!hasAccess(...permissionNeeded)) { + return ; + } + + return children; };