@@ -23,7 +23,7 @@ export type ResourceDefinition = {
2323const  getAuthCacheKey  =  ( service : ValidService ,  route : string )  => 
2424  `${ CACHE_KEY_PREFIX } ${ service }  _${ route }  ` ; 
2525
26- const  getCachedResponse  =  ( service : ValidService ,  route : string ) : CacheData  |  null  =>  { 
26+ export   const  getCachedResponse  =  ( service : ValidService ,  route : string ) : CacheData  |  null  =>  { 
2727  const  cached  =  sessionStorage . getItem ( getAuthCacheKey ( service ,  route ) ) ; 
2828  if  ( ! cached )  return  null ; 
2929
@@ -65,14 +65,16 @@ export const AuthGuard: React.FC<
6565    resourceDef : ResourceDefinition ; 
6666    children : ReactNode ; 
6767    isAppShell ?: boolean ; 
68+     loadingSkeleton ?: ReactNode ; 
6869  }  &  AcmAppShellProps 
69- >  =  ( {  resourceDef,  children,  isAppShell =  true ,  ...appShellProps  } )  =>  { 
70+ >  =  ( {  resourceDef,  children,  isAppShell =  true ,  loadingSkeleton ,   ...appShellProps  } )  =>  { 
7071  const  {  service,  validRoles }  =  resourceDef ; 
7172  const  {  baseEndpoint,  authCheckRoute,  friendlyName }  = 
7273    getRunEnvironmentConfig ( ) . ServiceConfiguration [ service ] ; 
7374  const  [ isAuthenticated ,  setIsAuthenticated ]  =  useState < boolean  |  null > ( null ) ; 
7475  const  [ username ,  setUsername ]  =  useState < string  |  null > ( null ) ; 
7576  const  [ roles ,  setRoles ]  =  useState < string [ ]  |  null > ( null ) ; 
77+   const  [ isLoading ,  setIsLoading ]  =  useState < boolean > ( true ) ; 
7678  const  api  =  useApi ( service ) ; 
7779
7880  useEffect ( ( )  =>  { 
@@ -88,6 +90,7 @@ export const AuthGuard: React.FC<
8890        } 
8991
9092        // Check for cached response first 
93+         setIsLoading ( true ) ; 
9194        const  cachedData  =  getCachedResponse ( service ,  authCheckRoute ) ; 
9295        if  ( cachedData  !==  null )  { 
9396          const  userRoles  =  cachedData . data . roles ; 
@@ -101,6 +104,7 @@ export const AuthGuard: React.FC<
101104          setUsername ( cachedData . data . username ) ; 
102105          setRoles ( cachedData . data . roles ) ; 
103106          setIsAuthenticated ( authenticated ) ; 
107+           setIsLoading ( false ) ; 
104108          return ; 
105109        } 
106110
@@ -120,15 +124,19 @@ export const AuthGuard: React.FC<
120124        setIsAuthenticated ( authenticated ) ; 
121125        setRoles ( result . data . roles ) ; 
122126        setUsername ( result . data . username ) ; 
127+         setIsLoading ( false ) ; 
123128      }  catch  ( e )  { 
124129        setIsAuthenticated ( false ) ; 
130+         setIsLoading ( false ) ; 
125131        console . error ( e ) ; 
126132      } 
127133    } 
128134
129135    getAuth ( ) ; 
130136  } ,  [ baseEndpoint ,  authCheckRoute ,  service ] ) ; 
131- 
137+   if  ( isLoading  &&  loadingSkeleton )  { 
138+     return  loadingSkeleton ; 
139+   } 
132140  if  ( isAuthenticated  ===  null )  { 
133141    if  ( isAppShell )  { 
134142      return  < FullScreenLoader  /> ; 
0 commit comments