Commit b4824d64 authored by Clément's avatar Clément

bugfix: avoid to call `auth.trackSession` to many times

parent 2ec5b638
Pipeline #5251 passed with stage
in 53 seconds
......@@ -33,6 +33,12 @@ class SIBAuth extends HTMLElement {
}
}
async trackSession() {
if (this.session) return this.session;
this.session = await new Promise(a => auth.trackSession(a));
return this.session;
}
/** @function
* @name disconnectedCallback
* Clear state and user, uninstall
......@@ -175,15 +181,10 @@ class SIBAuth extends HTMLElement {
* @return {User}
*/
// eslint-disable-next-line class-methods-use-this
getUserWebId() {
return new Promise((resolve) => {
auth.trackSession((session) => {
if (!session) {
return resolve(null);
}
return resolve(session.webId);
});
});
async getUserWebId() {
const session = await this.trackSession();
if (!session) return null;
return session.webId;
}
......@@ -193,15 +194,10 @@ class SIBAuth extends HTMLElement {
* @return {User}
*/
// eslint-disable-next-line class-methods-use-this
getUserIdToken() {
return new Promise((resolve) => {
auth.trackSession((session) => {
if (!session) {
return resolve(null);
}
return resolve(session.authorization && session.authorization.id_token);
});
});
async getUserIdToken() {
const session = await this.trackSession();
if (!session) return null;
return session.authorization && session.authorization.id_token;
}
/** @function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment