100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI updates: Bug fix for basic login not loading
Rich Turnerdc5e0f38cf6e
diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex b0bf3d33f..d726cd2c9 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -127,6 +127,7 @@ export interface ManagerConfig {loadTranslations?: string[];translationsLoadPath?: string;configureTranslationsOptions?: (i18next: InitOptions) => void;+ skipFallbackToBasicAuth?: boolean;basicLoginProvider?: (username: string | undefined, password: string | undefined) => PromiseLike<BasicLoginResult>;}@@ -636,9 +637,24 @@ export class Manager implements EventProviderFactory {console.log("Already initialised");}+ let success = false;this._config = normaliseConfig(config);- let success = await this.doAuthInit();+ if (this._config.auth === Auth.BASIC) {+ // BASIC auth will likely require UI so let's init translation at least+ success = await this.doTranslateInit() && success;+ success = await this.doAuthInit();+ } else {+ success = await this.doAuthInit();++ // If failed then we can assume keycloak auth requested but unavailable+ if (!success && !this._config.skipFallbackToBasicAuth) {+ // Try fallback to BASIC+ console.log("Falling back to basic auth");+ this._config.auth = Auth.BASIC;+ success = await this.doAuthInit();+ }+ }if (success) {success = await this.doInit();@@ -649,7 +665,6 @@ export class Manager implements EventProviderFactory {}success = await this.doConsoleInit() && success;-success = await this.doTranslateInit() && success;if (success) {@@ -668,6 +683,7 @@ export class Manager implements EventProviderFactory {this._ready = true;this._emitEvent(OREvent.READY);} else {+ (this._config as any) = undefined;console.warn("Failed to initialise the manager");}@@ -710,6 +726,9 @@ export class Manager implements EventProviderFactory {}protected async doTranslateInit(): Promise<boolean> {+ if (i18next.isInitialized) {+ return true;+ }i18next.on("initialized", (options) => {this._emitEvent(OREvent.TRANSLATE_INIT);@@ -795,13 +814,6 @@ export class Manager implements EventProviderFactory {break;case Auth.KEYCLOAK:success = await this.loadAndInitialiseKeycloak();-- if (!success) {- // Try fallback to BASIC- console.log("Falling back to basic auth");- this._config.auth = Auth.BASIC;- return this.doAuthInit();- }break;case Auth.NONE:// Nothing for us to do herediff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.tsindex 2153032d4..a9b113c63 100644--- a/ui/component/or-app/src/index.ts+++ b/ui/component/or-app/src/index.ts@@ -26,6 +26,7 @@ import {AnyAction, EnhancedStore, Unsubscribe} from "@reduxjs/toolkit";import {ThunkMiddleware} from "redux-thunk";import {AppStateKeyed, updatePage} from "./app";import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";+import { ORError } from "@openremote/core";const DefaultLogo = require("../images/logo.png");const DefaultMobileLogo = require("../images/logo-mobile.png");@@ -178,18 +179,40 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}};+ protected doAppConfigInit() {+ this.appConfig = this.appConfig || (this.appConfigProvider ? this.appConfigProvider(manager) : undefined);++ if (!this.appConfig) {+ return;+ }++ if (!this._config) {+ const realm = getRealmQueryParameter();+ this._config = this._getConfig(realm);+ }+ }+protected firstUpdated(_changedProperties: Map<PropertyKey, unknown>): void {super.firstUpdated(_changedProperties);- const managerConfig = this.managerConfig ? {...DEFAULT_MANAGER_CONFIG,...this.managerConfig} : DEFAULT_MANAGER_CONFIG;+ const managerConfig: ManagerConfig = this.managerConfig ? {...DEFAULT_MANAGER_CONFIG,...this.managerConfig} : DEFAULT_MANAGER_CONFIG;+ managerConfig.skipFallbackToBasicAuth = true; // We do this so we can load styling config before displaying basic loginmanagerConfig.basicLoginProvider = (u, p) => this.doBasicLogin(u, p);manager.addListener(this._onManagerEvent);console.info("Initialising the manager");- manager.init(managerConfig).then((success) => {+ manager.init(managerConfig).then(async (success) => {+ if (!success && manager.error === ORError.AUTH_FAILED && (!managerConfig.auth || managerConfig.auth === Auth.KEYCLOAK)) {+ this.doAppConfigInit();++ // Fallback to basic auth now styling is loaded+ managerConfig.auth = Auth.BASIC;+ success = await manager.init(managerConfig);+ }+if (success) {- this.appConfig = this.appConfig || (this.appConfigProvider ? this.appConfigProvider(manager) : undefined);+ this.doAppConfigInit();if (!this.appConfig) {showErrorDialog("appError.noConfig", document.body);@@ -197,6 +220,12 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {return;}+ if (!this._config) {+ showErrorDialog("appError.noConfig", document.body);+ console.error("No default AppConfig or realm specific config provided so cannot render");+ return;+ }+if (!this._store) {showErrorDialog("appError.noReduxStore", document.body);console.error("No Redux store supplied");@@ -210,15 +239,6 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}this._initialised = true;- const realm = getRealmQueryParameter();- const config = this._getConfig(realm);-- if (!config) {- console.error("No default AppConfig or realm specific config for requested realm: " + realm);- return;- } else {- this._config = config;- }this.appConfig.pages.forEach((pageProvider, index) => {if (pageProvider.routes) {