Skip to content

Commit 033a602

Browse files
idiidklieuwex
authored andcommitted
fix for #90 (#93)
Also maybe fixes #91.
1 parent a3cc44a commit 033a602

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/magister.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ class Magister {
394394
authorizeUrl += `&acr_values=tenant%3A${filteredName}`
395395

396396
if (!forceLogin && options.token) {
397-
return setToken(options.token)
397+
return setToken(options.token).then(retrieveAccount)
398398
}
399399

400400
// extract returnUrl
@@ -459,30 +459,31 @@ class Magister {
459459
}
460460

461461
// 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+
}
486487
}
487488
}
488489

0 commit comments

Comments
 (0)