@@ -26,7 +26,6 @@ import {
26
26
AuthenticationRouter ,
27
27
CardErrorBoundary ,
28
28
getPreLoginPath ,
29
- initializeAuthenticationDev ,
30
29
initializeAuthenticationProd ,
31
30
useSnackMessage ,
32
31
} from '@gridsuite/commons-ui' ;
@@ -37,14 +36,13 @@ import {
37
36
} from '../redux/actions' ;
38
37
import { AppState } from '../redux/reducer' ;
39
38
import {
39
+ ConfigSrv ,
40
40
ConfigParameter ,
41
41
ConfigParameters ,
42
- connectNotificationsWsUpdateConfig ,
43
- fetchAuthorizationCodeFlowFeatureFlag ,
44
- fetchConfigParameter ,
45
- fetchConfigParameters ,
46
- fetchValidateUser ,
47
- } from '../utils/rest-api' ;
42
+ UserAdminSrv ,
43
+ AppsMetadataSrv ,
44
+ } from '../services' ;
45
+ import { connectNotificationsWsUpdateConfig } from '../utils/rest-api' ;
48
46
import { UserManager } from 'oidc-client' ;
49
47
import {
50
48
APP_NAME ,
@@ -109,8 +107,10 @@ const App: FunctionComponent = () => {
109
107
const ws = connectNotificationsWsUpdateConfig ( ) ;
110
108
ws . onmessage = function ( event ) {
111
109
let eventData = JSON . parse ( event . data ) ;
112
- if ( eventData . headers && eventData . headers [ 'parameterName' ] ) {
113
- fetchConfigParameter ( eventData . headers [ 'parameterName' ] )
110
+ if ( eventData ?. headers ?. parameterName ) {
111
+ ConfigSrv . fetchConfigParameter (
112
+ eventData . headers . parameterName
113
+ )
114
114
. then ( ( param ) => updateParams ( [ param ] ) )
115
115
. catch ( ( error ) =>
116
116
snackError ( {
@@ -132,58 +132,40 @@ const App: FunctionComponent = () => {
132
132
path : '/silent-renew-callback' ,
133
133
} )
134
134
) ;
135
-
136
- const [ initialMatchSigninCallbackUrl ] = useState (
135
+ const [ initialMatchSignInCallbackUrl ] = useState (
137
136
useMatch ( {
138
137
path : '/sign-in-callback' ,
139
138
} )
140
139
) ;
141
140
142
- const initialize : ( ) => Promise < UserManager > = useCallback ( ( ) => {
143
- if ( process . env . REACT_APP_USE_AUTHENTICATION === 'true' ) {
144
- return fetchAuthorizationCodeFlowFeatureFlag ( ) . then (
145
- ( authorizationCodeFlowEnabled ) =>
146
- initializeAuthenticationProd (
147
- dispatch ,
148
- initialMatchSilentRenewCallbackUrl != null ,
149
- fetch ( 'idpSettings.json' ) ,
150
- fetchValidateUser ,
151
- authorizationCodeFlowEnabled ,
152
- initialMatchSigninCallbackUrl != null
153
- )
154
- ) ;
155
- } else {
156
- return initializeAuthenticationDev (
157
- dispatch ,
158
- initialMatchSilentRenewCallbackUrl != null ,
159
- ( ) =>
160
- new Promise ( ( resolve ) =>
161
- window . setTimeout ( ( ) => resolve ( true ) , 500 )
162
- ) ,
163
- initialMatchSigninCallbackUrl != null
164
- ) ;
165
- }
166
- // Note: initialMatchSilentRenewCallbackUrl and dispatch don't change
167
- } , [
168
- initialMatchSilentRenewCallbackUrl ,
169
- dispatch ,
170
- initialMatchSigninCallbackUrl ,
171
- ] ) ;
172
-
173
141
useEffect ( ( ) => {
174
- initialize ( )
142
+ AppsMetadataSrv . fetchAuthorizationCodeFlowFeatureFlag ( )
143
+ . then ( ( authorizationCodeFlowEnabled ) =>
144
+ initializeAuthenticationProd (
145
+ dispatch ,
146
+ initialMatchSilentRenewCallbackUrl != null ,
147
+ fetch ( 'idpSettings.json' ) ,
148
+ UserAdminSrv . fetchValidateUser ,
149
+ authorizationCodeFlowEnabled ,
150
+ initialMatchSignInCallbackUrl != null
151
+ )
152
+ )
175
153
. then ( ( userManager : UserManager | undefined ) => {
176
154
setUserManager ( { instance : userManager || null , error : null } ) ;
177
155
} )
178
156
. catch ( ( error : any ) => {
179
157
setUserManager ( { instance : null , error : error . message } ) ;
180
158
} ) ;
181
- // Note: initialize and initialMatchSilentRenewCallbackUrl won't change
182
- } , [ initialize , initialMatchSilentRenewCallbackUrl , dispatch ] ) ;
159
+ // Note: initialize and initialMatchSilentRenewCallbackUrl & initialMatchSignInCallbackUrl won't change
160
+ } , [
161
+ dispatch ,
162
+ initialMatchSilentRenewCallbackUrl ,
163
+ initialMatchSignInCallbackUrl ,
164
+ ] ) ;
183
165
184
166
useEffect ( ( ) => {
185
167
if ( user !== null ) {
186
- fetchConfigParameters ( COMMON_APP_NAME )
168
+ ConfigSrv . fetchConfigParameters ( COMMON_APP_NAME )
187
169
. then ( ( params ) => updateParams ( params ) )
188
170
. catch ( ( error ) =>
189
171
snackError ( {
@@ -192,7 +174,7 @@ const App: FunctionComponent = () => {
192
174
} )
193
175
) ;
194
176
195
- fetchConfigParameters ( APP_NAME )
177
+ ConfigSrv . fetchConfigParameters ( APP_NAME )
196
178
. then ( ( params ) => updateParams ( params ) )
197
179
. catch ( ( error ) =>
198
180
snackError ( {
0 commit comments