diff --git a/packages/auth/src/auth-keycloak.js b/packages/auth/src/auth-keycloak.js index db3ded9d87f5e8ef128ce5a3c0867f7d06a12164..dc4dcce28c259ac94a18b8132c16a0aa3bdd5a48 100644 --- a/packages/auth/src/auth-keycloak.js +++ b/packages/auth/src/auth-keycloak.js @@ -3,6 +3,7 @@ import JSONLD from '@dbp-toolkit/common/jsonld'; import {KeycloakWrapper} from './keycloak.js'; import {LoginStatus} from './util.js'; import {AdapterLitElement} from '@dbp-toolkit/provider/src/adapter-lit-element'; +import {send} from '@dbp-toolkit/common/notification'; /** * Keycloak auth web component @@ -219,17 +220,28 @@ export class AuthKeycloak extends AdapterLitElement { this._kcwrapper.addEventListener('changed', this._onKCChanged); const handleLogin = async () => { - if (this.forceLogin || this._kcwrapper.isLoggingIn()) { - this._setLoginStatus(LoginStatus.LOGGING_IN); - await this._kcwrapper.login({lang: this.lang, scope: this.scope || ''}); - } else if (this.tryLogin) { - this._setLoginStatus(LoginStatus.LOGGING_IN); - await this._kcwrapper.tryLogin(); - if (!this._authenticated) { + try { + if (this.forceLogin || this._kcwrapper.isLoggingIn()) { + this._setLoginStatus(LoginStatus.LOGGING_IN); + await this._kcwrapper.login({lang: this.lang, scope: this.scope || ''}); + } else if (this.tryLogin) { + this._setLoginStatus(LoginStatus.LOGGING_IN); + await this._kcwrapper.tryLogin(); + if (!this._authenticated) { + this._setLoginStatus(LoginStatus.LOGGED_OUT); + } + } else { this._setLoginStatus(LoginStatus.LOGGED_OUT); } - } else { + } catch (error) { + // In case the keycloak server is offline for example this._setLoginStatus(LoginStatus.LOGGED_OUT); + send({ + summary: this._i18n.t('login-failed'), + type: 'danger', + timeout: 5, + }); + throw error; } }; diff --git a/packages/auth/src/i18n/de/translation.json b/packages/auth/src/i18n/de/translation.json index 1fa9113346b481be1aa1110c85aebe59a152cc5a..46959e2a80e2c8502a7b4f14d36253d54a567007 100644 --- a/packages/auth/src/i18n/de/translation.json +++ b/packages/auth/src/i18n/de/translation.json @@ -1,4 +1,5 @@ { "login": "Anmelden", + "login-failed": "Kommunikation mit dem Anmeldeserver fehlgeschlagen", "logout": "Abmelden" } diff --git a/packages/auth/src/i18n/en/translation.json b/packages/auth/src/i18n/en/translation.json index 8bfc42ac59dd49d3e115f2a8668a582e0028c255..1cd772c555a60ed294eb68b37958ede544314ac2 100644 --- a/packages/auth/src/i18n/en/translation.json +++ b/packages/auth/src/i18n/en/translation.json @@ -1,4 +1,5 @@ { "login": "Login", + "login-failed": "Communication with the login server failed", "logout": "Logout" }