diff --git a/packages/auth/README.md b/packages/auth/README.md index 7b78c1e54fc764d5da178b7db0000bbe319b37e5..41364011e92bda5245065e3770b0c22683d24cf9 100644 --- a/packages/auth/README.md +++ b/packages/auth/README.md @@ -36,10 +36,6 @@ npm i @dbp-toolkit/auth - `silent-check-sso-redirect-uri` (optional): URI or path to a separate page for checking the login session in an iframe, see https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter - `scope` (optional): Space separated list of scopes to request. These scopes get added in addition to the default ones, assuming the scope is in the optional scopes list of the Keycloak client in use. -### Events to listen to - -- `dbp-auth-person-init`: Keycloak person init event - the person entity was loaded from the server - ## Login Button ### Usage diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js index 160ea89564298394f01057884f6fe053fa5c089b..2be63569ee668a7283e3bf66ca52a1ee3a0bd317 100644 --- a/packages/auth/src/auth-keycloak.js +++ b/packages/auth/src/auth-keycloak.js @@ -16,8 +16,7 @@ import {AdapterLitElement} from "@dbp-toolkit/provider/src/adapter-lit-element"; * window.DBPAuthTokenParsed: Keycloak token content * window.DBPUserFullName: Full name of the user * window.DBPPersonId: Person identifier of the user - * window.DBPPerson: Person json object of the user (optional, enable by setting the `load-person` attribute, - * which will dispatch a `dbp-auth-person-init` event when loaded) + * window.DBPPerson: Person json object of the user (optional, enable by setting the `load-person` attribute) */ export class AuthKeycloak extends AdapterLitElement { constructor() { @@ -43,9 +42,6 @@ export class AuthKeycloak extends AdapterLitElement { this.scope = null; this.idpHint = ''; - // Create the events - this.personInitEvent = new CustomEvent("dbp-auth-person-init", { "detail": "KeyCloak person init event", bubbles: true, composed: true }); - this._onKCChanged = this._onKCChanged.bind(this); } @@ -127,7 +123,6 @@ export class AuthKeycloak extends AdapterLitElement { .then((person) => { that.person = person; window.DBPPerson = person; - that.dispatchEvent(that.personInitEvent); this._setLoginStatus(this._loginStatus, true); }); }, {}, that.lang); diff --git a/packages/auth/src/login-button.js b/packages/auth/src/login-button.js index 435916e4ee5478e3da90863987a98d666ac8e734..8465c5879efb132a9ebf9e9adc83a06e4319bd24 100644 --- a/packages/auth/src/login-button.js +++ b/packages/auth/src/login-button.js @@ -88,7 +88,6 @@ export class LoginButton extends ScopedElementsMixin(LitElement) { this._bus = new EventBus(); this._bus.subscribe('auth-update', (data) => { - console.log(data); this._loginData = data; }); } diff --git a/packages/person-profile/src/dbp-person-profile-demo.js b/packages/person-profile/src/dbp-person-profile-demo.js index 375636e5820233c13f2cc79cb59cd89781c72430..4328ef6a38601ff52d7cf912bcb4053b20c7a9ad 100644 --- a/packages/person-profile/src/dbp-person-profile-demo.js +++ b/packages/person-profile/src/dbp-person-profile-demo.js @@ -8,6 +8,7 @@ import * as commonUtils from '@dbp-toolkit/common/utils'; import * as commonStyles from '@dbp-toolkit/common/styles'; import $ from 'jquery'; import {PersonSelect} from '@dbp-toolkit/person-select'; +import {EventBus} from '@dbp-toolkit/common'; export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) { constructor() { @@ -43,11 +44,14 @@ export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) { i18n.changeLanguage(this.lang); const that = this; - this.updateComplete.then(()=>{ - window.addEventListener("dbp-auth-person-init", () => { - that.person = window.DBPPersonId; - }); + this._bus = new EventBus(); + this._bus.subscribe('auth-update', (data) => { + if (data.person) { + this.person = data.person.identifier; + } + }); + this.updateComplete.then(()=>{ const personSelect = that._(this.constructor.getScopedTagName('dbp-person-select')); personSelect.onchange = function () { that.selectedPerson = $(this).data("object").identifier; @@ -56,6 +60,11 @@ export class PersonProfileDemo extends ScopedElementsMixin(DBPLitElement) { }); } + disconnectedCallback() { + this._bus.close(); + super.disconnectedCallback(); + } + static get styles() { // language=css return css`