...
 
Commits (2)
...@@ -68,9 +68,9 @@ ...@@ -68,9 +68,9 @@
</script> </script>
<script type="module"> <script type="module">
import { SIBBase, store } from 'https://unpkg.com/@startinblox/core@0.7'; import { store } from 'https://unpkg.com/@startinblox/core@0.8';
const sibAuth = document.querySelector('sib-auth');
class TestComponent extends SIBBase { class TestComponent extends HTMLElement {
async connectedCallback() { async connectedCallback() {
login.onclick = () => this.triggerLogin(); login.onclick = () => this.triggerLogin();
logout.onclick = () => this.triggerLogout(); logout.onclick = () => this.triggerLogout();
...@@ -79,15 +79,15 @@ ...@@ -79,15 +79,15 @@
} }
async triggerLogin() { async triggerLogin() {
await this.login(); await sibAuth.login();
} }
async triggerLogout() { async triggerLogout() {
await this.logout(); await sibAuth.logout();
} }
async update() { async update() {
let user = await this.getUser(); let user = await sibAuth.getUser();
let idToken = await this.getUserIdToken(); let idToken = await sibAuth.getUserIdToken();
if (!user) { if (!user) {
result.innerHTML = `Vous n'êtes pas connecté !`; result.innerHTML = `Vous n'êtes pas connecté !`;
return; return;
......
import auth from 'https://dev.jspm.io/solid-auth-client'; import auth from 'https://dev.jspm.io/solid-auth-client';
import { Helpers, SIBBase } from 'https://unpkg.com/@startinblox/core@0.7'; import { Helpers } from 'https://unpkg.com/@startinblox/core@0.8';
const baseUrl = import.meta.url.replace(/\/[^/]*$/, ''); const baseUrl = import.meta.url.replace(/\/[^/]*$/, '');
Helpers.importCSS(`${baseUrl}/sib-auth.css`); Helpers.importCSS(`${baseUrl}/sib-auth.css`);
...@@ -48,14 +48,6 @@ class SIBAuth extends HTMLElement { ...@@ -48,14 +48,6 @@ class SIBAuth extends HTMLElement {
* to provide auth information on all SIB component * to provide auth information on all SIB component
*/ */
install() { install() {
SIBBase.prototype.login = () => this.login();
SIBBase.prototype.logout = () => this.logout();
SIBBase.prototype.getUserIdToken = () => this.getUserIdToken();
SIBBase.prototype.getUser = async () => {
const id = await this.getUserWebId();
if (!id) return null;
return { '@id': id };
};
this.bindUserObserver = new MutationObserver((mutations) => { this.bindUserObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => { mutations.forEach((mutation) => {
if (mutation.type === 'attributes') { if (mutation.type === 'attributes') {
...@@ -86,10 +78,6 @@ class SIBAuth extends HTMLElement { ...@@ -86,10 +78,6 @@ class SIBAuth extends HTMLElement {
*/ */
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
uninstall() { uninstall() {
SIBBase.prototype.login = null;
SIBBase.prototype.logout = null;
SIBBase.prototype.getUser = null;
SIBBase.prototype.getUserIdToken = null;
this.bindUserObserver.disconnect(); this.bindUserObserver.disconnect();
} }
...@@ -201,7 +189,7 @@ class SIBAuth extends HTMLElement { ...@@ -201,7 +189,7 @@ class SIBAuth extends HTMLElement {
/** @function /** @function
* @name getUserIdToken * @name getUserIdToken
* Return IdToken or undefined * Return IdToken or null
* @return {User} * @return {User}
*/ */
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
...@@ -216,6 +204,17 @@ class SIBAuth extends HTMLElement { ...@@ -216,6 +204,17 @@ class SIBAuth extends HTMLElement {
}); });
} }
/** @function
* @name getUser
* Return user or null
* @return {User}
*/
async getUser() {
const id = await this.getUserWebId();
if (!id) return null;
return { '@id': id };
}
/** @function /** @function
* @name login * @name login
* Try to login, if favorite provider is set, trigger login, if not, select provider * Try to login, if favorite provider is set, trigger login, if not, select provider
......