mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-24 12:06:15 +01:00
[PM-2676] Fix web set environment urls after state init (#5632)
* [PM-2676] Fix web set env urls after state init. * [PM-2676] Add note to remove workaround
This commit is contained in:
parent
ff18a5b905
commit
4124f7bdc8
@ -38,11 +38,15 @@ export class InitService {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
return async () => {
|
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();
|
await this.stateService.init();
|
||||||
|
|
||||||
const urls = process.env.URLS as Urls;
|
const urls = process.env.URLS as Urls;
|
||||||
urls.base ??= this.win.location.origin;
|
urls.base ??= this.win.location.origin;
|
||||||
this.environmentService.setUrls(urls);
|
this.environmentService.setUrls(urls);
|
||||||
|
this.environmentService.initialized = true;
|
||||||
|
|
||||||
setTimeout(() => this.notificationsService.init(), 3000);
|
setTimeout(() => this.notificationsService.init(), 3000);
|
||||||
(this.vaultTimeoutService as VaultTimeoutService).init(true);
|
(this.vaultTimeoutService as VaultTimeoutService).init(true);
|
||||||
|
@ -88,11 +88,10 @@ export class EnvironmentSelectorComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateEnvironmentInfo() {
|
async updateEnvironmentInfo() {
|
||||||
|
this.selectedEnvironment = this.environmentService.selectedRegion;
|
||||||
this.euServerFlagEnabled = await this.configService.getFeatureFlagBool(
|
this.euServerFlagEnabled = await this.configService.getFeatureFlagBool(
|
||||||
FeatureFlag.DisplayEuEnvironmentFlag
|
FeatureFlag.DisplayEuEnvironmentFlag
|
||||||
);
|
);
|
||||||
|
|
||||||
this.selectedEnvironment = this.environmentService.selectedRegion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
|
@ -28,6 +28,7 @@ export abstract class EnvironmentService {
|
|||||||
usUrls: Urls;
|
usUrls: Urls;
|
||||||
euUrls: Urls;
|
euUrls: Urls;
|
||||||
selectedRegion?: Region;
|
selectedRegion?: Region;
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
hasBaseUrl: () => boolean;
|
hasBaseUrl: () => boolean;
|
||||||
getNotificationsUrl: () => string;
|
getNotificationsUrl: () => string;
|
||||||
|
@ -12,6 +12,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
|||||||
private readonly urlsSubject = new Subject<void>();
|
private readonly urlsSubject = new Subject<void>();
|
||||||
urls: Observable<void> = this.urlsSubject.asObservable();
|
urls: Observable<void> = this.urlsSubject.asObservable();
|
||||||
selectedRegion?: Region;
|
selectedRegion?: Region;
|
||||||
|
initialized = true;
|
||||||
|
|
||||||
protected baseUrl: string;
|
protected baseUrl: string;
|
||||||
protected webVaultUrl: string;
|
protected webVaultUrl: string;
|
||||||
@ -49,6 +50,9 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
|||||||
this.stateService.activeAccount$
|
this.stateService.activeAccount$
|
||||||
.pipe(
|
.pipe(
|
||||||
concatMap(async () => {
|
concatMap(async () => {
|
||||||
|
if (!this.initialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
await this.setUrlsFromStorage();
|
await this.setUrlsFromStorage();
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -157,22 +161,23 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
|||||||
|
|
||||||
// fix environment urls for old users
|
// fix environment urls for old users
|
||||||
if (savedUrls.base === "https://vault.bitwarden.com") {
|
if (savedUrls.base === "https://vault.bitwarden.com") {
|
||||||
this.setRegion(Region.US);
|
await this.setRegion(Region.US);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (savedUrls.base === "https://vault.bitwarden.eu") {
|
if (savedUrls.base === "https://vault.bitwarden.eu") {
|
||||||
this.setRegion(Region.EU);
|
await this.setRegion(Region.EU);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (region) {
|
switch (region) {
|
||||||
case Region.EU:
|
case Region.EU:
|
||||||
this.setRegion(Region.EU);
|
await this.setRegion(Region.EU);
|
||||||
return;
|
return;
|
||||||
case Region.US:
|
case Region.US:
|
||||||
this.setRegion(Region.US);
|
await this.setRegion(Region.US);
|
||||||
return;
|
return;
|
||||||
case Region.SelfHosted:
|
case Region.SelfHosted:
|
||||||
|
case null:
|
||||||
default:
|
default:
|
||||||
this.baseUrl = envUrls.base = savedUrls.base;
|
this.baseUrl = envUrls.base = savedUrls.base;
|
||||||
this.webVaultUrl = savedUrls.webVault;
|
this.webVaultUrl = savedUrls.webVault;
|
||||||
@ -182,9 +187,9 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
|||||||
this.notificationsUrl = savedUrls.notifications;
|
this.notificationsUrl = savedUrls.notifications;
|
||||||
this.eventsUrl = envUrls.events = savedUrls.events;
|
this.eventsUrl = envUrls.events = savedUrls.events;
|
||||||
this.keyConnectorUrl = savedUrls.keyConnector;
|
this.keyConnectorUrl = savedUrls.keyConnector;
|
||||||
|
await this.setRegion(Region.SelfHosted);
|
||||||
// scimUrl is not saved to storage
|
// scimUrl is not saved to storage
|
||||||
this.urlsSubject.next();
|
this.urlsSubject.next();
|
||||||
this.setRegion(Region.SelfHosted);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,7 +275,7 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
|
|||||||
case Region.SelfHosted:
|
case Region.SelfHosted:
|
||||||
// if user saves with empty fields, default to US
|
// if user saves with empty fields, default to US
|
||||||
if (this.isEmpty()) {
|
if (this.isEmpty()) {
|
||||||
this.setRegion(Region.US);
|
await this.setRegion(Region.US);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user