@@ -256,6 +256,20 @@ function extendUiSchemaWithHistory(
256
256
} ;
257
257
}
258
258
259
+ function getSupportedAuthMethods ( session : SessionState ) : string [ ] {
260
+ const {
261
+ serverInfo : { capabilities } ,
262
+ } = session ;
263
+ const { openid : { providers } = { providers : [ ] } } = capabilities ;
264
+ // Check which of our known auth implementations are supported by the server.
265
+ const supportedAuthMethods = KNOWN_AUTH_METHODS . filter (
266
+ a => a in capabilities
267
+ ) ;
268
+ // Add an auth method for each single openid provider supported by the server.
269
+ const openIdMethods = providers . map ( provider => `openid-${ provider . name } ` ) ;
270
+ return [ ANONYMOUS_AUTH ] . concat ( supportedAuthMethods ) . concat ( openIdMethods ) ;
271
+ }
272
+
259
273
type AuthFormProps = {
260
274
session : SessionState ;
261
275
servers : ServerEntry [ ] ;
@@ -281,35 +295,43 @@ export default function AuthForm({
281
295
const { schema : currentSchema , uiSchema : curentUiSchema } =
282
296
authSchemas ( authType ) ;
283
297
298
+ const [ showSpinner , setshowSpinner ] = useState ( false ) ;
284
299
const [ schema , setSchema ] = useState ( currentSchema ) ;
285
300
const [ uiSchema , setUiSchema ] = useState ( curentUiSchema ) ;
286
301
const [ formData , setFormData ] = useState ( {
287
302
authType,
288
303
server : getServerByPriority ( servers ) ,
289
304
} ) ;
290
305
291
- const getSupportedAuthMethods = ( ) : string [ ] => {
292
- const {
293
- serverInfo : { capabilities } ,
294
- } = session ;
295
- const { openid : { providers } = { providers : [ ] } } = capabilities ;
296
- // Check which of our known auth implementations are supported by the server.
297
- const supportedAuthMethods = KNOWN_AUTH_METHODS . filter (
298
- a => a in capabilities
299
- ) ;
300
- // Add an auth method for each single openid provider supported by the server.
301
- const openIdMethods = providers . map ( provider => `openid-${ provider . name } ` ) ;
302
- return [ ANONYMOUS_AUTH ] . concat ( supportedAuthMethods ) . concat ( openIdMethods ) ;
306
+ const serverChangeCallback = ( ) => {
307
+ serverChange ( ) ;
303
308
} ;
304
309
310
+ const serverInfoCallback = auth => {
311
+ getServerInfo ( auth ) ;
312
+ setshowSpinner ( false ) ;
313
+ } ;
314
+
315
+ const authMethods = getSupportedAuthMethods ( session ) ;
316
+ const singleAuthMethod = authMethods . length === 1 ;
317
+ const finalSchema = extendSchemaWithHistory ( schema , servers , authMethods ) ;
318
+ const finalUiSchema = extendUiSchemaWithHistory (
319
+ uiSchema ,
320
+ servers ,
321
+ clearServers ,
322
+ serverInfoCallback ,
323
+ serverChangeCallback ,
324
+ singleAuthMethod
325
+ ) ;
326
+
305
327
const onChange = ( { formData : updatedData } : RJSFSchema ) => {
306
328
if ( formData . server !== updatedData . server ) {
329
+ setshowSpinner ( true ) ;
307
330
const newServer = servers . find ( x => x . server === updatedData . server ) ;
308
331
updatedData . authType = newServer ?. authType || ANONYMOUS_AUTH ;
309
332
}
310
333
const { authType } = updatedData ;
311
- const { uiSchema } = authSchemas ( authType ) ;
312
- const { schema } = authSchemas ( authType ) ;
334
+ const { schema, uiSchema } = authSchemas ( authType ) ;
313
335
const omitCredentials =
314
336
[ ANONYMOUS_AUTH , "fxa" , "portier" ] . includes ( authType ) ||
315
337
authType . startsWith ( "openid-" ) ;
@@ -355,17 +377,6 @@ export default function AuthForm({
355
377
}
356
378
} ;
357
379
358
- const authMethods = getSupportedAuthMethods ( ) ;
359
- const singleAuthMethod = authMethods . length === 1 ;
360
- const finalSchema = extendSchemaWithHistory ( schema , servers , authMethods ) ;
361
- const finalUiSchema = extendUiSchemaWithHistory (
362
- uiSchema ,
363
- servers ,
364
- clearServers ,
365
- getServerInfo ,
366
- serverChange ,
367
- singleAuthMethod
368
- ) ;
369
380
return (
370
381
< div className = "card" >
371
382
< div className = "card-body" >
@@ -375,6 +386,7 @@ export default function AuthForm({
375
386
formData = { formData }
376
387
onChange = { onChange }
377
388
onSubmit = { onSubmit }
389
+ showSpinner = { showSpinner }
378
390
>
379
391
< button type = "submit" className = "btn btn-info" >
380
392
{ "Sign in using " }
0 commit comments