Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue caused by wired key with disabled OATH application #134

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading