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 { ...@@ -39,6 +39,12 @@ class SIBAuth extends HTMLElement {
}, timeout); }, timeout);
} }
async trackSession() {
if (this.session) return this.session;
this.session = await new Promise(a => auth.trackSession(a));
return this.session;
}
/** @function /** @function
* @name disconnectedCallback * @name disconnectedCallback
* Clear state and user, uninstall * Clear state and user, uninstall
...@@ -181,15 +187,10 @@ class SIBAuth extends HTMLElement { ...@@ -181,15 +187,10 @@ class SIBAuth extends HTMLElement {
* @return {User} * @return {User}
*/ */
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
getUserWebId() { async getUserWebId() {
return new Promise((resolve) => { const session = await this.trackSession();
auth.trackSession((session) => { if (!session) return null;
if (!session) { return session.webId;
return resolve(null);
}
return resolve(session.webId);
});
});
} }
...@@ -199,15 +200,10 @@ class SIBAuth extends HTMLElement { ...@@ -199,15 +200,10 @@ class SIBAuth extends HTMLElement {
* @return {User} * @return {User}
*/ */
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
getUserIdToken() { async getUserIdToken() {
return new Promise((resolve) => { const session = await this.trackSession();
auth.trackSession((session) => { if (!session) return null;
if (!session) { return session.authorization && session.authorization.id_token;
return resolve(null);
}
return resolve(session.authorization && session.authorization.id_token);
});
});
} }
/** @function /** @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