File tree Expand file tree Collapse file tree 5 files changed +50
-40
lines changed Expand file tree Collapse file tree 5 files changed +50
-40
lines changed Original file line number Diff line number Diff line change 11{
22  "backendUrl" : " http://localhost:3000"  ,
33  "landscape" : " LOCAL"  ,
4-   "documentationBaseUrl" : " http://localhost:3000" 
4+   "documentationBaseUrl" : " http://localhost:3000"  ,
5+   "oidcConfig" : {
6+     "clientId" : " clientId"  ,
7+     "issuerUrl" : " issuer-url"  ,
8+     "scopes" : [
9+       " " 
10+     ]
11+   }
512}
Original file line number Diff line number Diff line change 1- import  {  ReactNode ,   use  }  from  'react' ; 
2- import  {  AuthProvider ,   AuthProviderProps  }  from  'react-oidc-context' ; 
1+ import  {  ReactNode  }  from  'react' ; 
2+ import  {  AuthProvider  }  from  'react-oidc-context' ; 
33import  {  useFrontendConfig  }  from  './FrontendConfigContext.tsx' ; 
4- import  {  LoadCrateKubeConfig  }  from  '../lib/oidc/crate .ts' ; 
4+ import  {  buildAuthProviderProps  }  from  '../lib/oidc/onboardingApi .ts' ; 
55
66interface  AuthProviderOnboardingProps  { 
77  children ?: ReactNode ; 
88} 
99
10- // Promise needs to be cached 
11- // https://react.dev/blog/2024/12/05/react-19#use-does-not-support-promises-created-in-render 
12- const  fetchAuthPromiseCache  =  new  Map < string ,  Promise < AuthProviderProps > > ( ) ; 
13- 
1410export  function  AuthProviderOnboarding ( { 
1511  children, 
1612} : AuthProviderOnboardingProps )  { 
17-   const  {  backendUrl }  =  useFrontendConfig ( ) ; 
18- 
19-   const  fetchAuthConfigPromise  = 
20-     fetchAuthPromiseCache . get ( backendUrl )  ??  LoadCrateKubeConfig ( backendUrl ) ; 
21-   fetchAuthPromiseCache . set ( backendUrl ,  fetchAuthConfigPromise ) ; 
22- 
23-   const  authConfig  =  use ( fetchAuthConfigPromise ) ; 
13+   const  {  oidcConfig }  =  useFrontendConfig ( ) ; 
2414
15+   const  authConfig  =  buildAuthProviderProps ( oidcConfig ) ; 
2516  return  < AuthProvider  { ...authConfig } > { children } </ AuthProvider > ; 
2617} 
Original file line number Diff line number Diff line change 11import  {  ReactNode ,  createContext ,  use  }  from  'react' ; 
22import  {  DocLinkCreator  }  from  '../lib/shared/links' ; 
3+ import  {  OIDCConfig  }  from  '../lib/oidc/onboardingApi' ; 
34
45export  enum  Landscape  { 
56  Live  =  'LIVE' , 
@@ -9,10 +10,14 @@ export enum Landscape {
910  Local  =  'LOCAL' , 
1011} 
1112
12- interface   FrontendConfigContextProps  { 
13+ type   FrontendConfig   =  { 
1314  backendUrl : string ; 
1415  landscape ?: Landscape ; 
1516  documentationBaseUrl : string ; 
17+   oidcConfig : OIDCConfig ; 
18+ } 
19+ 
20+ interface  FrontendConfigContextProps  extends  FrontendConfig  { 
1621  links : DocLinkCreator ; 
1722} 
1823
@@ -21,7 +26,7 @@ export const FrontendConfigContext = createContext<FrontendConfigContextProps |
2126) ; 
2227
2328
24- const  fetchPromise  =  fetch ( '/frontend-config.json' ) . then ( ( res )  =>  res . json ( ) ) ; 
29+ const  fetchPromise  =  fetch ( '/frontend-config.json' ) . then ( ( res )  =>  res . json ( ) ) . then ( ( data )   =>   data   as   FrontendConfig ) ; 
2530
2631interface  FrontendConfigProviderProps  { 
2732  children : ReactNode ; 
@@ -32,11 +37,8 @@ export function FrontendConfigProvider({ children }: FrontendConfigProviderProps
3237  const  docLinks  =  new  DocLinkCreator ( config . documentationBaseUrl ) ; 
3338  const  value : FrontendConfigContextProps  =  { 
3439    links : docLinks , 
35-     backendUrl : config . backendUrl , 
36-     landscape : config . landscape , 
37-     documentationBaseUrl : config . documentationBaseUrl , 
40+     ...config , 
3841  } ; 
39- 
4042  return  ( 
4143    < FrontendConfigContext  value = { value } > { children } </ FrontendConfigContext > 
4244  ) ; 
  Load Diff This file was deleted. 
Original file line number Diff line number Diff line change 1+ import  {  WebStorageStateStore  }  from  "oidc-client-ts" ; 
2+ import  {  AuthProviderProps  }  from  "react-oidc-context" ; 
3+ 
4+ export  interface  OIDCConfig  { 
5+   clientId : string ; 
6+   issuerUrl : string ; 
7+   scopes : string [ ] ; 
8+ } 
9+ 
10+ export  function  buildAuthProviderProps ( oidcConfig : OIDCConfig )  { 
11+   const  userStore  =  new  WebStorageStateStore ( {  store : window . localStorage  } ) ; 
12+ 
13+   const  props : AuthProviderProps  =  { 
14+     authority : oidcConfig . issuerUrl , 
15+     client_id : oidcConfig . clientId , 
16+     redirect_uri : getDefaultRedirectUri ( ) , 
17+     scope : oidcConfig . scopes . join ( ' ' ) , 
18+     userStore : userStore , 
19+     automaticSilentRenew : false ,  // we show a window instead that asks the user to renew the token 
20+     onSigninCallback : ( )  =>  { 
21+       window . history . replaceState ( { } ,  document . title ,  window . location . pathname ) ; 
22+     } , 
23+   } ; 
24+   return  props ; 
25+ } 
26+ 
27+ function  getDefaultRedirectUri ( )  { 
28+   return  window . location . origin ; 
29+ } 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments