Skip to content

Commit 993d84c

Browse files
committed
Fixes issue where the disable OTP modal would be presented after app returned from background.
1 parent ab3f463 commit 993d84c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Authenticator/Model/MainViewModel.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ class MainViewModel: ObservableObject {
102102
}
103103
}
104104
} catch {
105-
self?.sessionTask?.cancel()
106-
self?.presentDisableOTP = true
105+
// Only handle .otpEnabledError by presenting the disable OTP modal
106+
if let sessionError = error as? OATHSessionError, sessionError == .otpEnabledError {
107+
self?.sessionTask?.cancel()
108+
self?.presentDisableOTP = true
109+
}
107110
}
108111
}
109112
}

Authenticator/Model/OATHSession.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
import Foundation
1818

19-
enum OATHSessionError: Error, LocalizedError {
19+
enum OATHSessionError: Error, LocalizedError, Equatable {
20+
2021
case credentialAlreadyPresent(YKFOATHCredentialTemplate);
22+
case otpEnabledError;
2123

2224
public var errorDescription: String? {
2325
switch self {
2426
case .credentialAlreadyPresent(let credential):
2527
return "There's already an account named \(credential.issuer.isEmpty == false ? "\(credential.issuer), \(credential.accountName)" : credential.accountName) on this YubiKey."
28+
case .otpEnabledError:
29+
return "Yubico OTP enabled"
2630
}
2731
}
2832
}
@@ -153,7 +157,7 @@ class OATHSessionHandler: NSObject, YKFManagerDelegate {
153157
guard let deviceInfo else { continuation.resume(throwing: error!); return }
154158
guard let configuration = deviceInfo.configuration else { continuation.resume(throwing: "Error!!!"); return }
155159
guard !configuration.isEnabled(.OTP, overTransport: .USB) || SettingsConfig.isOTPOverUSBIgnored(deviceId: deviceInfo.serialNumber) else {
156-
continuation.resume(throwing: "OTP enabled error")
160+
continuation.resume(throwing: OATHSessionError.otpEnabledError)
157161
self.wiredContinuation = nil
158162
self.wiredConnectionCallback = nil
159163
return

0 commit comments

Comments
 (0)