6
6
*/
7
7
8
8
import React , { useCallback , useEffect , useState } from 'react' ;
9
-
10
9
import { useDispatch , useSelector } from 'react-redux' ;
11
-
12
10
import {
13
11
Navigate ,
14
12
Route ,
15
13
Routes ,
16
- useNavigate ,
17
14
useLocation ,
15
+ useMatch ,
16
+ useNavigate ,
18
17
} from 'react-router-dom' ;
19
-
20
18
import {
21
19
selectComputedLanguage ,
22
20
selectLanguage ,
23
21
selectTheme ,
24
22
} from '../redux/actions' ;
25
-
26
23
import {
27
24
AuthenticationRouter ,
28
25
CardErrorBoundary ,
29
26
getPreLoginPath ,
30
27
initializeAuthenticationProd ,
28
+ useSnackMessage ,
31
29
} from '@gridsuite/commons-ui' ;
32
-
33
- import { useMatch } from 'react-router-dom' ;
34
30
import { FormattedMessage } from 'react-intl' ;
35
-
36
31
import {
37
32
connectNotificationsWsUpdateConfig ,
38
- fetchAuthorizationCodeFlowFeatureFlag ,
39
33
fetchConfigParameter ,
40
34
fetchConfigParameters ,
35
+ fetchIdpSettings ,
41
36
fetchValidateUser ,
42
37
} from '../utils/rest-api' ;
43
38
import {
@@ -47,7 +42,6 @@ import {
47
42
PARAM_THEME ,
48
43
} from '../utils/config-params' ;
49
44
import { getComputedLanguage } from '../utils/language' ;
50
- import { useSnackMessage } from '@gridsuite/commons-ui' ;
51
45
import AppTopBar from './app-top-bar' ;
52
46
import Grid from '@mui/material/Grid' ;
53
47
import TreeViewsContainer from './tree-views-container' ;
@@ -149,23 +143,23 @@ const App = () => {
149
143
) ;
150
144
151
145
useEffect ( ( ) => {
152
- fetchAuthorizationCodeFlowFeatureFlag ( )
153
- . then ( ( authorizationCodeFlowEnabled ) => {
154
- return initializeAuthenticationProd (
155
- dispatch ,
156
- initialMatchSilentRenewCallbackUrl != null ,
157
- fetch ( 'idpSettings.json' ) ,
158
- fetchValidateUser ,
159
- authorizationCodeFlowEnabled ,
160
- initialMatchSigninCallbackUrl != null
161
- ) ;
162
- } )
163
- . then ( ( userManager ) => {
164
- setUserManager ( { instance : userManager , error : null } ) ;
165
- } )
166
- . catch ( function ( error ) {
146
+ // need subfunction when async as suggested by rule react-hooks/exhaustive-deps
147
+ ( async function initializeAuthentication ( ) {
148
+ try {
149
+ setUserManager ( {
150
+ instance : await initializeAuthenticationProd (
151
+ dispatch ,
152
+ initialMatchSilentRenewCallbackUrl != null ,
153
+ fetchIdpSettings ,
154
+ fetchValidateUser ,
155
+ initialMatchSigninCallbackUrl != null
156
+ ) ,
157
+ error : null ,
158
+ } ) ;
159
+ } catch ( error ) {
167
160
setUserManager ( { instance : null , error : error . message } ) ;
168
- } ) ;
161
+ }
162
+ } ) ( ) ;
169
163
// Note: initialMatchSilentRenewCallbackUrl and dispatch don't change
170
164
} , [
171
165
initialMatchSilentRenewCallbackUrl ,
0 commit comments