@ -179,7 +179,7 @@ export class StateService<
@@ -179,7 +179,7 @@ export class StateService<
}
async addAccount ( account : TAccount ) {
account = await this . setAccountEnvironmentUrls ( account ) ;
account = await this . setAccountEnvironment ( account ) ;
await this . updateState ( async ( state ) = > {
state . authenticatedAccounts . push ( account . profile . userId ) ;
await this . storageService . save ( keys . authenticatedAccounts , state . authenticatedAccounts ) ;
@ -2606,8 +2606,9 @@ export class StateService<
@@ -2606,8 +2606,9 @@ export class StateService<
await this . defaultOnDiskLocalOptions ( )
)
) ;
// EnvironmentUrls are set before authenticating and should override whatever is stored from any previous session
// EnvironmentUrls and region a re set before authenticating and should override whatever is stored from any previous session
const environmentUrls = account . settings . environmentUrls ;
const region = account . settings . region ;
if ( storedAccount ? . settings != null ) {
account . settings = storedAccount . settings ;
} else if ( await this . storageService . has ( keys . tempAccountSettings ) ) {
@ -2615,6 +2616,8 @@ export class StateService<
@@ -2615,6 +2616,8 @@ export class StateService<
await this . storageService . remove ( keys . tempAccountSettings ) ;
}
account . settings . environmentUrls = environmentUrls ;
account . settings . region = region ;
if (
account . settings . vaultTimeoutAction === VaultTimeoutAction . LogOut &&
account . settings . vaultTimeout != null
@ -2642,6 +2645,7 @@ export class StateService<
@@ -2642,6 +2645,7 @@ export class StateService<
) ;
if ( storedAccount ? . settings != null ) {
storedAccount . settings . environmentUrls = account . settings . environmentUrls ;
storedAccount . settings . region = account . settings . region ;
account . settings = storedAccount . settings ;
}
await this . storageService . save (
@ -2664,6 +2668,7 @@ export class StateService<
@@ -2664,6 +2668,7 @@ export class StateService<
) ;
if ( storedAccount ? . settings != null ) {
storedAccount . settings . environmentUrls = account . settings . environmentUrls ;
storedAccount . settings . region = account . settings . region ;
account . settings = storedAccount . settings ;
}
await this . storageService . save (
@ -2812,7 +2817,9 @@ export class StateService<
@@ -2812,7 +2817,9 @@ export class StateService<
return Object . assign ( this . createAccount ( ) , persistentAccountInformation ) ;
}
protected async setAccountEnvironmentUrls ( account : TAccount ) : Promise < TAccount > {
// The environment urls and region are selected before login and are transferred here to an authenticated account
protected async setAccountEnvironment ( account : TAccount ) : Promise < TAccount > {
account . settings . region = await this . getGlobalRegion ( ) ;
account . settings . environmentUrls = await this . getGlobalEnvironmentUrls ( ) ;
return account ;
}
@ -2822,6 +2829,11 @@ export class StateService<
@@ -2822,6 +2829,11 @@ export class StateService<
return ( await this . getGlobals ( options ) ) . environmentUrls ? ? new EnvironmentUrls ( ) ;
}
protected async getGlobalRegion ( options? : StorageOptions ) : Promise < string > {
options = this . reconcileOptions ( options , await this . defaultOnDiskOptions ( ) ) ;
return ( await this . getGlobals ( options ) ) . region ? ? null ;
}
protected async clearDecryptedDataForActiveUser ( ) : Promise < void > {
await this . updateState ( async ( state ) = > {
const userId = state ? . activeUserId ;