@@ -60,8 +60,6 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
60
60
)
61
61
const [ loggedOut , setLoggedOut ] = useState ( false )
62
62
63
- const basicAuthEnabled = settings [ "acl.basic.auth.realm.enabled" ]
64
-
65
63
const setAuthToken = ( tokenResponse : AuthPayload ) => {
66
64
if ( tokenResponse . access_token ) {
67
65
setValue (
@@ -187,25 +185,41 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
187
185
)
188
186
// Stop loading and display the login state
189
187
} else {
190
- checkIfBasicAuth ( )
188
+ uiAuthLogin ( )
191
189
}
192
190
}
193
- } else if ( basicAuthEnabled ) {
194
- // run a simple query to force basic auth by browser
195
- await fetch ( `${ window . location . origin } /exec?query=select 42` )
191
+ } else if (
192
+ // We need to explicitly check for the Boolean value, because the settings response might not come up from the API
193
+ // yet, and therefore be still undefined by default
194
+ typeof settings [ "acl.basic.auth.realm.enabled" ] !== "undefined"
195
+ ) {
196
+ if ( settings [ "acl.basic.auth.realm.enabled" ] ) {
197
+ await basicAuthLogin ( )
198
+ } else {
199
+ // Subscribe for any subsequent REST 401 responses (incorrect token, etc)
200
+ eventBus . subscribe ( EventType . MSG_CONNECTION_UNAUTHORIZED , ( ) => {
201
+ logout ( )
202
+ } )
203
+
204
+ //username + pwd via login page
205
+ uiAuthLogin ( )
206
+ }
207
+ }
208
+ }
209
+
210
+ const basicAuthLogin = async ( ) => {
211
+ // run a simple query to force basic auth by browser
212
+ const response = await fetch (
213
+ `${ window . location . origin } /exec?query=select 42` ,
214
+ )
215
+ if ( response . status === 200 ) {
196
216
setReady ( true )
197
217
} else {
198
- // Subscribe for any subsequent REST 401 responses (incorrect token, etc)
199
- eventBus . subscribe ( EventType . MSG_CONNECTION_UNAUTHORIZED , ( ) => {
200
- logout ( )
201
- } )
202
-
203
- //username + pwd via login page
204
- checkIfBasicAuth ( )
218
+ await basicAuthLogin ( )
205
219
}
206
220
}
207
221
208
- const checkIfBasicAuth = ( ) => {
222
+ const uiAuthLogin = ( ) => {
209
223
// Check if user is authenticated already with basic auth
210
224
const token = getValue ( StoreKey . REST_TOKEN )
211
225
if ( token ) {
@@ -289,7 +303,7 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
289
303
< Error
290
304
errorMessage = { errorMessage }
291
305
onLogout = { logout }
292
- basicAuthEnabled = { basicAuthEnabled }
306
+ basicAuthEnabled = { settings [ "acl.basic.auth.realm.enabled" ] ?? false }
293
307
/>
294
308
)
295
309
} else if ( loading ) {
0 commit comments