diff --git a/BitwardenShared/UI/Auth/AuthRouterTests.swift b/BitwardenShared/UI/Auth/AuthRouterTests.swift index ca17241c4..4e3dca251 100644 --- a/BitwardenShared/UI/Auth/AuthRouterTests.swift +++ b/BitwardenShared/UI/Auth/AuthRouterTests.swift @@ -1083,6 +1083,33 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ ) ) XCTAssertEqual(route, .complete) + XCTAssertEqual(authRepository.setActiveAccountId, active.profile.userId) + } + + /// `handleAndRoute(_ :)` redirects `.switchAccount()` to `.vaultUnlock` when switching to a + /// locked inactive account. + func test_handleAndRoute_switchAccount_toInactive() async { + let active = Account.fixture() + let inactive = Account.fixture(profile: .fixture(userId: "2")) + authRepository.activeAccount = active + authRepository.altAccounts = [inactive] + authRepository.isLockedResult = .success(true) + stateService.isAuthenticated["2"] = true + let route = await subject.handleAndRoute( + .action( + .switchAccount(isAutomatic: true, userId: inactive.profile.userId) + ) + ) + XCTAssertEqual( + route, + .vaultUnlock( + inactive, + animated: false, + attemptAutomaticBiometricUnlock: true, + didSwitchAccountAutomatically: true + ) + ) + XCTAssertEqual(authRepository.setActiveAccountId, inactive.profile.userId) } /// `handleAndRoute(_ :)` redirects `.switchAccount()` to `.landingSoftLoggedOut` when that @@ -1099,5 +1126,6 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_ ) ) XCTAssertEqual(route, .landingSoftLoggedOut(email: account.profile.email)) + XCTAssertEqual(authRepository.setActiveAccountId, account.profile.userId) } } diff --git a/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift b/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift index 04d21ee87..4a799567b 100644 --- a/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift +++ b/BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift @@ -306,17 +306,6 @@ extension AuthRouter { /// - Returns: A suggested route for the active account with state pre-configured. /// func switchAccountRedirect(isAutomatic: Bool, userId: String) async -> AuthRoute { - if let account = try? await services.authRepository.getAccount(), - userId == account.profile.userId { - return await handleAndRoute( - .accountBecameActive( - account, - animated: false, - attemptAutomaticBiometricUnlock: true, - didSwitchAccountAutomatically: false - ) - ) - } do { let activeAccount = try await services.authRepository.setActiveAccount(userId: userId) // Setup the unlock route for the active account.