Skip to content
Snippets Groups Projects
Commit 06350c06 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

auth: handle the case when the keycloak server is offline

Up until now it would throw and never set a login status. This would lead
to the login process never completing, and in our case the app-shell
would never show the app and only show a white page.

Instead set the status to logged out and show a notification.
parent 827a8562
No related branches found
No related tags found
No related merge requests found
Pipeline #105496 failed
...@@ -3,6 +3,7 @@ import JSONLD from '@dbp-toolkit/common/jsonld'; ...@@ -3,6 +3,7 @@ import JSONLD from '@dbp-toolkit/common/jsonld';
import {KeycloakWrapper} from './keycloak.js'; import {KeycloakWrapper} from './keycloak.js';
import {LoginStatus} from './util.js'; import {LoginStatus} from './util.js';
import {AdapterLitElement} from '@dbp-toolkit/provider/src/adapter-lit-element'; import {AdapterLitElement} from '@dbp-toolkit/provider/src/adapter-lit-element';
import {send} from '@dbp-toolkit/common/notification';
/** /**
* Keycloak auth web component * Keycloak auth web component
...@@ -219,17 +220,28 @@ export class AuthKeycloak extends AdapterLitElement { ...@@ -219,17 +220,28 @@ export class AuthKeycloak extends AdapterLitElement {
this._kcwrapper.addEventListener('changed', this._onKCChanged); this._kcwrapper.addEventListener('changed', this._onKCChanged);
const handleLogin = async () => { const handleLogin = async () => {
if (this.forceLogin || this._kcwrapper.isLoggingIn()) { try {
this._setLoginStatus(LoginStatus.LOGGING_IN); if (this.forceLogin || this._kcwrapper.isLoggingIn()) {
await this._kcwrapper.login({lang: this.lang, scope: this.scope || ''}); this._setLoginStatus(LoginStatus.LOGGING_IN);
} else if (this.tryLogin) { await this._kcwrapper.login({lang: this.lang, scope: this.scope || ''});
this._setLoginStatus(LoginStatus.LOGGING_IN); } else if (this.tryLogin) {
await this._kcwrapper.tryLogin(); this._setLoginStatus(LoginStatus.LOGGING_IN);
if (!this._authenticated) { await this._kcwrapper.tryLogin();
if (!this._authenticated) {
this._setLoginStatus(LoginStatus.LOGGED_OUT);
}
} else {
this._setLoginStatus(LoginStatus.LOGGED_OUT); this._setLoginStatus(LoginStatus.LOGGED_OUT);
} }
} else { } catch (error) {
// In case the keycloak server is offline for example
this._setLoginStatus(LoginStatus.LOGGED_OUT); this._setLoginStatus(LoginStatus.LOGGED_OUT);
send({
summary: this._i18n.t('login-failed'),
type: 'danger',
timeout: 5,
});
throw error;
} }
}; };
......
{ {
"login": "Anmelden", "login": "Anmelden",
"login-failed": "Kommunikation mit dem Anmeldeserver fehlgeschlagen",
"logout": "Abmelden" "logout": "Abmelden"
} }
{ {
"login": "Login", "login": "Login",
"login-failed": "Communication with the login server failed",
"logout": "Logout" "logout": "Logout"
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment