Commit 2ec5b638 authored by Matthieu Fesselier's avatar Matthieu Fesselier

Merge branch 'sib-core-v0.8' into 'master'

update: use sib-core v0.8

See merge request !13
parents eabebab5 455ff77d
Pipeline #4523 passed with stage
in 52 seconds
......@@ -68,9 +68,9 @@
</script>
<script type="module">
import { SIBBase, store } from 'https://unpkg.com/@startinblox/core@0.7';
class TestComponent extends SIBBase {
import { store } from 'https://unpkg.com/@startinblox/core@0.8';
const sibAuth = document.querySelector('sib-auth');
class TestComponent extends HTMLElement {
async connectedCallback() {
login.onclick = () => this.triggerLogin();
logout.onclick = () => this.triggerLogout();
......@@ -79,15 +79,15 @@
}
async triggerLogin() {
await this.login();
await sibAuth.login();
}
async triggerLogout() {
await this.logout();
await sibAuth.logout();
}
async update() {
let user = await this.getUser();
let idToken = await this.getUserIdToken();
let user = await sibAuth.getUser();
let idToken = await sibAuth.getUserIdToken();
if (!user) {
result.innerHTML = `Vous n'êtes pas connecté !`;
return;
......
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(/\/[^/]*$/, '');
Helpers.importCSS(`${baseUrl}/sib-auth.css`);
......@@ -48,14 +48,6 @@ class SIBAuth extends HTMLElement {
* to provide auth information on all SIB component
*/
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) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes') {
......@@ -86,10 +78,6 @@ class SIBAuth extends HTMLElement {
*/
// eslint-disable-next-line class-methods-use-this
uninstall() {
SIBBase.prototype.login = null;
SIBBase.prototype.logout = null;
SIBBase.prototype.getUser = null;
SIBBase.prototype.getUserIdToken = null;
this.bindUserObserver.disconnect();
}
......@@ -201,7 +189,7 @@ class SIBAuth extends HTMLElement {
/** @function
* @name getUserIdToken
* Return IdToken or undefined
* Return IdToken or null
* @return {User}
*/
// eslint-disable-next-line class-methods-use-this
......@@ -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
* @name login
* Try to login, if favorite provider is set, trigger login, if not, select provider
......
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