Commit 08bd1c7e authored by Matthieu Fesselier's avatar Matthieu Fesselier

Merge branch 'fix/EventEmitter-warning' into 'master'

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

Closes #24

See merge request !16
parents 092d9dbc b4824d64
Pipeline #5261 passed with stage
in 53 seconds
......@@ -39,6 +39,12 @@ class SIBAuth extends HTMLElement {
}, timeout);
}
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
......@@ -181,15 +187,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;
}
......@@ -199,15 +200,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