@@ -20,15 +20,17 @@ type HeaderProps = {
2020
2121// Determine once whether MSAL authentication is enabled, so the hooks inside
2222// UserProfile (which require MsalProvider in the tree) are only mounted when safe.
23+ // window.appConfig is set in main.jsx after fetching /config; falls back to
24+ // false when the config has not loaded or auth is disabled.
2325const isAuthEnabled = ( ) : boolean => {
24- // window.appConfig is set in main.jsx after fetching /config
25- // Falls back to false when the config has not loaded or auth is disabled.
26- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27- const cfg = ( typeof window !== "undefined" ? ( window as any ) . appConfig : null ) ;
28- return Boolean ( cfg && cfg . ENABLE_AUTH ) ;
26+ if ( typeof window === "undefined" ) return false ;
27+ return Boolean ( window . appConfig && window . appConfig . ENABLE_AUTH ) ;
2928} ;
3029
3130const Header : React . FC < HeaderProps > = ( { title = "Contoso" , subtitle, children } ) => {
31+ const authEnabled = isAuthEnabled ( ) ;
32+ const hasToolbarContent = React . Children . count ( children ) > 0 || authEnabled ;
33+
3234 return (
3335 < header
3436 style = { {
@@ -68,17 +70,20 @@ const Header: React.FC<HeaderProps> = ({ title = "Contoso", subtitle, children }
6870 </ Subtitle2 >
6971 </ div >
7072
71- { /* HEADER TOOLBAR (rendered only if passed as a child) */ }
72- < div
73- style = { {
74- display : "flex" ,
75- alignItems : "center" ,
76- gap : "8px" ,
77- } }
78- >
79- { children }
80- { isAuthEnabled ( ) && < UserProfile /> }
81- </ div >
73+ { /* HEADER TOOLBAR (rendered only when there is toolbar content
74+ or the auth-enabled user profile menu to display) */ }
75+ { hasToolbarContent && (
76+ < div
77+ style = { {
78+ display : "flex" ,
79+ alignItems : "center" ,
80+ gap : "8px" ,
81+ } }
82+ >
83+ { children }
84+ { authEnabled && < UserProfile /> }
85+ </ div >
86+ ) }
8287 </ header >
8388 ) ;
8489} ;
0 commit comments