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 Fix: Insights can now be opened without authentication again (#1850)
Martin Peeters35cdfbaed30e
diff --git a/ui/app/insights/src/pages/page-view.ts b/ui/app/insights/src/pages/page-view.tsindex c881774ac..4bc58c1df 100644--- a/ui/app/insights/src/pages/page-view.ts+++ b/ui/app/insights/src/pages/page-view.ts@@ -79,8 +79,10 @@ export class PageView extends Page<AppStateKeyed> {super(props);// Register user- const userPromise = manager.rest.api.UserResource.getCurrent().then((response: any) => { this._userId = response.data.id; });- this.registerPromise('user', userPromise, true, true);+ if(manager.authenticated) {+ const userPromise = manager.rest.api.UserResource.getCurrent().then((response: any) => { this._userId = response.data.id; });+ this.registerPromise('user', userPromise, true, true);+ }// Load available realmsconst realmPromise = manager.rest.api.RealmResource.getAccessible().then((response: any) => { this._loadedRealms = response.data; });diff --git a/ui/component/core/src/index.ts b/ui/component/core/src/index.tsindex 08801704c..5106eb3d0 100644--- a/ui/component/core/src/index.ts+++ b/ui/component/core/src/index.ts@@ -249,7 +249,9 @@ export class Manager implements EventProviderFactory {if (lang) {i18next.changeLanguage(lang);this.console.storeData("LANGUAGE", lang);- this.updateKeycloakUserLanguage(lang).catch(e => console.error(e));+ if(this.authenticated) {+ this.updateKeycloakUserLanguage(lang).catch(e => console.error(e));+ }}}@@ -686,7 +688,7 @@ export class Manager implements EventProviderFactory {*/public async getUserPreferredLanguage(keycloak = this._keycloak): Promise<string | undefined> {- if(keycloak) {+ if(keycloak && keycloak.authenticated) {const profile: Keycloak.KeycloakProfile | undefined = keycloak?.profile || await keycloak?.loadUserProfile();if(profile?.attributes) {const attributes = new Map(Object.entries(profile.attributes));@@ -703,12 +705,13 @@ export class Manager implements EventProviderFactory {}}- protected async updateKeycloakUserLanguage(lang: string, keycloak = this._keycloak, rest = this.rest): Promise<void> {- if(!keycloak) {+ protected async updateKeycloakUserLanguage(lang: string, rest = this.rest): Promise<void> {+ if(!this.authenticated) {+ console.warn("Tried updating user language, but the user is not authenticated.");return;}if(!rest) {- console.warn("Tried updating user language in keycloak, but the REST API is not initialized yet.");+ console.warn("Tried updating user language, but the REST API is not initialized yet.");return;}await rest.api.UserResource.updateCurrentUserLocale(lang, { headers: { "Content-Type": "application/json" } });