@@ -394,7 +394,7 @@ class Magister {
394
394
authorizeUrl += `&acr_values=tenant%3A${ filteredName } `
395
395
396
396
if ( ! forceLogin && options . token ) {
397
- return setToken ( options . token )
397
+ return setToken ( options . token ) . then ( retrieveAccount )
398
398
}
399
399
400
400
// extract returnUrl
@@ -459,30 +459,31 @@ class Magister {
459
459
}
460
460
461
461
// extract bearer token
462
- const token =
463
- await this . http . get ( `https://accounts.magister.net${ returnUrl } ` , {
464
- redirect : 'manual' ,
465
- headers : {
466
- Cookie : authRes . headers . get ( 'set-cookie' ) ,
467
- 'X-XSRF-TOKEN' : xsrf ,
468
- } ,
469
- } )
470
- . then ( res => res . headers . get ( 'Location' )
471
- . split ( '&access_token=' ) [ 1 ]
472
- . split ( '&' ) [ 0 ] )
473
- . then ( setToken )
474
- const accountData =
475
- await this . http . get ( `${ schoolUrl } /api/account` ) . then ( res => res . json ( ) )
476
- const id = accountData . Persoon . Id
477
-
478
- // REVIEW: do we want to make profileInfo a function?
479
- this . profileInfo = new ProfileInfo ( this , accountData . Persoon )
480
- this . _privileges = new Privileges ( this , accountData . Groep [ 0 ] . Privileges )
481
-
482
- this . _personUrl = `${ schoolUrl } /api/personen/${ id } `
483
- this . _pupilUrl = `${ schoolUrl } /api/leerlingen/${ id } `
484
-
485
- return token
462
+ return await this . http . get ( `https://accounts.magister.net${ returnUrl } ` , {
463
+ redirect : 'manual' ,
464
+ headers : {
465
+ Cookie : authRes . headers . get ( 'set-cookie' ) ,
466
+ 'X-XSRF-TOKEN' : xsrf ,
467
+ } ,
468
+ } )
469
+ . then ( res => res . headers . get ( 'Location' )
470
+ . split ( '&access_token=' ) [ 1 ]
471
+ . split ( '&' ) [ 0 ] )
472
+ . then ( setToken )
473
+ . then ( retrieveAccount )
474
+
475
+ async function retrieveAccount ( ) {
476
+ const accountData =
477
+ await self . http . get ( `${ schoolUrl } /api/account` ) . then ( res => res . json ( ) )
478
+ const id = accountData . Persoon . Id
479
+
480
+ // REVIEW: do we want to make profileInfo a function?
481
+ self . profileInfo = new ProfileInfo ( self , accountData . Persoon )
482
+ self . _privileges = new Privileges ( self , accountData . Groep [ 0 ] . Privileges )
483
+
484
+ self . _personUrl = `${ schoolUrl } /api/personen/${ id } `
485
+ self . _pupilUrl = `${ schoolUrl } /api/leerlingen/${ id } `
486
+ }
486
487
}
487
488
}
488
489
0 commit comments