diff --git a/apps/web/src/app/core/init.service.ts b/apps/web/src/app/core/init.service.ts index 60eeeeea18..4a2ef2f495 100644 --- a/apps/web/src/app/core/init.service.ts +++ b/apps/web/src/app/core/init.service.ts @@ -38,11 +38,15 @@ export class InitService { init() { return async () => { + // Workaround to ignore stateService.activeAccount until process.env.URLS are set + // TODO: Remove this when implementing ticket PM-2637 + this.environmentService.initialized = false; await this.stateService.init(); const urls = process.env.URLS as Urls; urls.base ??= this.win.location.origin; this.environmentService.setUrls(urls); + this.environmentService.initialized = true; setTimeout(() => this.notificationsService.init(), 3000); (this.vaultTimeoutService as VaultTimeoutService).init(true); diff --git a/libs/angular/src/auth/components/environment-selector.component.ts b/libs/angular/src/auth/components/environment-selector.component.ts index 7989e0f2ca..d622b4c6db 100644 --- a/libs/angular/src/auth/components/environment-selector.component.ts +++ b/libs/angular/src/auth/components/environment-selector.component.ts @@ -88,11 +88,10 @@ export class EnvironmentSelectorComponent implements OnInit, OnDestroy { } async updateEnvironmentInfo() { + this.selectedEnvironment = this.environmentService.selectedRegion; this.euServerFlagEnabled = await this.configService.getFeatureFlagBool( FeatureFlag.DisplayEuEnvironmentFlag ); - - this.selectedEnvironment = this.environmentService.selectedRegion; } close() { diff --git a/libs/common/src/platform/abstractions/environment.service.ts b/libs/common/src/platform/abstractions/environment.service.ts index 68327f4fd6..aa963baf0a 100644 --- a/libs/common/src/platform/abstractions/environment.service.ts +++ b/libs/common/src/platform/abstractions/environment.service.ts @@ -28,6 +28,7 @@ export abstract class EnvironmentService { usUrls: Urls; euUrls: Urls; selectedRegion?: Region; + initialized = true; hasBaseUrl: () => boolean; getNotificationsUrl: () => string; diff --git a/libs/common/src/platform/services/environment.service.ts b/libs/common/src/platform/services/environment.service.ts index b2f62a22b1..6b27f9c13c 100644 --- a/libs/common/src/platform/services/environment.service.ts +++ b/libs/common/src/platform/services/environment.service.ts @@ -12,6 +12,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { private readonly urlsSubject = new Subject(); urls: Observable = this.urlsSubject.asObservable(); selectedRegion?: Region; + initialized = true; protected baseUrl: string; protected webVaultUrl: string; @@ -49,6 +50,9 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { this.stateService.activeAccount$ .pipe( concatMap(async () => { + if (!this.initialized) { + return; + } await this.setUrlsFromStorage(); }) ) @@ -157,22 +161,23 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { // fix environment urls for old users if (savedUrls.base === "https://vault.bitwarden.com") { - this.setRegion(Region.US); + await this.setRegion(Region.US); return; } if (savedUrls.base === "https://vault.bitwarden.eu") { - this.setRegion(Region.EU); + await this.setRegion(Region.EU); return; } switch (region) { case Region.EU: - this.setRegion(Region.EU); + await this.setRegion(Region.EU); return; case Region.US: - this.setRegion(Region.US); + await this.setRegion(Region.US); return; case Region.SelfHosted: + case null: default: this.baseUrl = envUrls.base = savedUrls.base; this.webVaultUrl = savedUrls.webVault; @@ -182,9 +187,9 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { this.notificationsUrl = savedUrls.notifications; this.eventsUrl = envUrls.events = savedUrls.events; this.keyConnectorUrl = savedUrls.keyConnector; + await this.setRegion(Region.SelfHosted); // scimUrl is not saved to storage this.urlsSubject.next(); - this.setRegion(Region.SelfHosted); break; } } @@ -270,7 +275,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction { case Region.SelfHosted: // if user saves with empty fields, default to US if (this.isEmpty()) { - this.setRegion(Region.US); + await this.setRegion(Region.US); } break; }