Skip to content

Commit

Permalink
Fixes issue caused by wired key with disabled OATH application.
Browse files Browse the repository at this point in the history
  • Loading branch information
jensutbult committed Nov 13, 2023
1 parent cb9af95 commit 642052c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 11 additions & 6 deletions Authenticator/Model/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class MainViewModel: ObservableObject {
@Published var presentDisableOTP: Bool = false
@Published var passwordEntryMessage: String = ""
@Published var isKeyPluggedIn: Bool = false
@Published var error: Error?
@Published var sessionError: Error?
@Published var connectionError: Error?

@Published var showTouchToast: Bool = false

Expand Down Expand Up @@ -101,14 +102,17 @@ class MainViewModel: ObservableObject {
self?.otherAccounts.removeAll()
self?.accountsLoaded = false
self?.isKeyPluggedIn = false
self?.error = error
self?.sessionError = error
}
}
} catch {
self?.sessionTask?.cancel()
// Only handle .otpEnabledError by presenting the disable OTP modal
if let sessionError = error as? OATHSessionError, sessionError == .otpEnabledError {
self?.sessionTask?.cancel()
self?.presentDisableOTP = true
} else {
self?.connectionError = error
}
}
}
Expand All @@ -125,7 +129,8 @@ class MainViewModel: ObservableObject {
otherAccounts.removeAll()
accountsLoaded = false
isKeyPluggedIn = false
error = nil
sessionError = nil
connectionError = nil
}

@MainActor private func updateAccount(_ account: Account) async {
Expand Down Expand Up @@ -229,7 +234,7 @@ class MainViewModel: ObservableObject {
await updateAccounts(using: session)
} catch {
YubiKitManager.shared.stopNFCConnection(withErrorMessage: "Something went wrong")
self.error = error
self.sessionError = error
}
}
}
Expand Down Expand Up @@ -349,7 +354,7 @@ class MainViewModel: ObservableObject {
}
} else {
YubiKitManager.shared.stopNFCConnection()
self.error = error
self.sessionError = error
}
}

Expand Down Expand Up @@ -390,7 +395,7 @@ class MainViewModel: ObservableObject {
try self.accessKeySecureStore.setValue(accessKey, useAuthentication: self.passwordPreferences.useScreenLock(keyIdentifier: keyIdentifier), for: keyIdentifier)
} catch {
self.passwordPreferences.resetPasswordPreference(keyIdentifier: keyIdentifier)
self.error = error
self.sessionError = error
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Authenticator/UI/ErrorAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import SwiftUI

extension View {
func errorAlert(error: Binding<Error?>, buttonTitle: String = "OK") -> some View {
func errorAlert(error: Binding<Error?>, buttonTitle: String = "OK", handler: (() -> Void)? = nil) -> some View {
let localizedAlertError = LocalizedAlertError(error: error.wrappedValue)
return alert(isPresented: .constant(localizedAlertError != nil), error: localizedAlertError) { _ in
Button(buttonTitle) {
error.wrappedValue = nil
handler?()
}
} message: { error in
Text(error.recoverySuggestion ?? "")
Expand Down
3 changes: 2 additions & 1 deletion Authenticator/UI/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ struct MainView: View {
Button("Never for this YubiKey") { model.passwordSaveType.send(.some(.never)) }
Button("Not now" , role: .cancel) { model.passwordSaveType.send(nil) }
}
.errorAlert(error: $model.error)
.errorAlert(error: $model.sessionError)
.errorAlert(error: $model.connectionError) { model.start() }
.onAppear {
if ApplicationSettingsViewModel().isNFCOnAppLaunchEnabled {
model.updateAccountsOverNFC()
Expand Down

0 comments on commit 642052c

Please sign in to comment.