1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 18:23:31 +00:00

[PM-3000] Add Environment URLs to Account Switcher (#5978)

* add server url to account switcher tab

* add serverUrl to SwitcherAccount(s)

* refactor serverUrl getter

* cleanup urls

* adjust styling

* remove SwitcherAccount class

* remove authenticationStatus from AccountProfile

* rename to inactiveAccounts for clarity

* move business logic to environmentService

* use tokenService instead of stateService

* cleanup type and comments

* remove unused property

* replace magic strings

* remove unused function

* minor refactoring

* refactor to use environmentService insead of getServerConfig

* use Utils.getHost() instead of Utils.getDomain()

* create getHost() method

* remove comment

* get base url as fallback

* resolve eslint error

* Update apps/desktop/src/app/layout/account-switcher.component.html

Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>

---------

Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
This commit is contained in:
rr-bw
2023-11-15 11:02:11 -08:00
committed by GitHub
parent cd19fc5133
commit 90bad00cb5
7 changed files with 98 additions and 76 deletions

View File

@@ -4,9 +4,11 @@ import { EnvironmentUrls } from "../../auth/models/domain/environment-urls";
import {
EnvironmentService as EnvironmentServiceAbstraction,
Region,
RegionDomain,
Urls,
} from "../abstractions/environment.service";
import { StateService } from "../abstractions/state.service";
import { Utils } from "../misc/utils";
export class EnvironmentService implements EnvironmentServiceAbstraction {
private readonly urlsSubject = new ReplaySubject<void>(1);
@@ -283,6 +285,28 @@ export class EnvironmentService implements EnvironmentServiceAbstraction {
);
}
async getHost(userId?: string) {
const region = await this.getRegion(userId ? userId : null);
switch (region) {
case Region.US:
return RegionDomain.US;
case Region.EU:
return RegionDomain.EU;
default: {
// Environment is self-hosted
const envUrls = await this.stateService.getEnvironmentUrls(
userId ? { userId: userId } : null
);
return Utils.getHost(envUrls.webVault || envUrls.base);
}
}
}
private async getRegion(userId?: string) {
return this.stateService.getRegion(userId ? { userId: userId } : null);
}
async setRegion(region: Region) {
this.selectedRegion = region;
await this.stateService.setRegion(region);