mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
Auth/PM-5712 - Extension & Desktop Account Switcher - Fix incorrect env showing when adding new accounts (#13362)
* PM-5712 - Refactor env service to require user id instead of having global and active user state fallbacks per working session with Justin. * PM-5712 - AccountSwitcherService tests - fix tests and add env assertions.
This commit is contained in:
@@ -271,19 +271,8 @@ export class DefaultEnvironmentService implements EnvironmentService {
|
||||
}
|
||||
}
|
||||
|
||||
getEnvironment$(userId?: UserId): Observable<Environment | undefined> {
|
||||
if (userId == null) {
|
||||
return this.environment$;
|
||||
}
|
||||
|
||||
return this.activeAccountId$.pipe(
|
||||
switchMap((activeUserId) => {
|
||||
// Previous rules dictated that we only get from user scoped state if there is an active user.
|
||||
if (activeUserId == null) {
|
||||
return this.globalState.state$;
|
||||
}
|
||||
return this.stateProvider.getUser(userId ?? activeUserId, USER_ENVIRONMENT_KEY).state$;
|
||||
}),
|
||||
getEnvironment$(userId: UserId): Observable<Environment | undefined> {
|
||||
return this.stateProvider.getUser(userId, USER_ENVIRONMENT_KEY).state$.pipe(
|
||||
map((state) => {
|
||||
return this.buildEnvironment(state?.region, state?.urls);
|
||||
}),
|
||||
@@ -294,7 +283,10 @@ export class DefaultEnvironmentService implements EnvironmentService {
|
||||
* @deprecated Use getEnvironment$ instead.
|
||||
*/
|
||||
async getEnvironment(userId?: UserId): Promise<Environment | undefined> {
|
||||
return firstValueFrom(this.getEnvironment$(userId));
|
||||
// Add backwards compatibility support for null userId
|
||||
const definedUserId = userId ?? (await firstValueFrom(this.activeAccountId$));
|
||||
|
||||
return firstValueFrom(this.getEnvironment$(definedUserId));
|
||||
}
|
||||
|
||||
async seedUserEnvironment(userId: UserId) {
|
||||
|
||||
Reference in New Issue
Block a user