11import { LoadingSpinner } from '@openops/components/ui' ;
2- import { Suspense , useEffect } from 'react' ;
2+ import { Suspense , useEffect , useState } from 'react' ;
33
44import { flagsHooks } from '@/app/common/hooks/flags-hooks' ;
5- import { setupResponseInterceptor } from '@/app/interceptors' ;
5+ import {
6+ setupRequestInterceptor ,
7+ setupResponseInterceptor ,
8+ } from '@/app/interceptors' ;
69
710type InitialDataGuardProps = {
811 children : React . ReactNode ;
@@ -11,16 +14,31 @@ export const InitialDataGuard = ({
1114 children,
1215} : Readonly < InitialDataGuardProps > ) => {
1316 const { data : flags } = flagsHooks . useFlags ( ) ;
17+ const [ interceptorsReady , setInterceptorsReady ] = useState ( false ) ;
1418
1519 useEffect ( ( ) => {
1620 if ( ! flags ) {
1721 console . error ( 'Missing flags for response interceptor configuration' ) ;
22+ return ;
1823 }
24+ const isFederatedAuth = Boolean ( flags ?. FEDERATED_LOGIN_ENABLED ) ;
25+ setupRequestInterceptor ( {
26+ isFederatedAuth,
27+ } ) ;
1928 setupResponseInterceptor ( {
20- isFederatedAuth : Boolean ( flags ?. FEDERATED_LOGIN_ENABLED ) ,
29+ isFederatedAuth,
2130 } ) ;
31+ setInterceptorsReady ( true ) ;
2232 } , [ flags ] ) ;
2333
34+ if ( ! interceptorsReady ) {
35+ return (
36+ < div className = "bg-background flex h-screen w-screen items-center justify-center " >
37+ < LoadingSpinner size = { 50 } > </ LoadingSpinner >
38+ </ div >
39+ ) ;
40+ }
41+
2442 return (
2543 < Suspense
2644 fallback = {
0 commit comments