...
 
Commits (2)
...@@ -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
......