Skip to content

Commit ed4269b

Browse files
authored
[Auth] Better keychain error descriptions (#13600)
1 parent fab6834 commit ed4269b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ class AuthErrorUtils: NSObject {
371371
}
372372

373373
static func keychainError(function: String, status: OSStatus) -> Error {
374-
let reason = "\(function) (\(status))"
374+
let message = SecCopyErrorMessageString(status, nil) as String? ?? ""
375+
let reason = "\(function) (\(status)) \(message)"
375376
return error(code: .keychainError, userInfo: [NSLocalizedFailureReasonErrorKey: reason])
376377
}
377378

FirebaseAuth/Tests/SampleSwift/AuthenticationExample/ViewControllers/SettingsViewController.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,19 @@ class SettingsViewController: UIViewController, DataSourceProviderDelegate {
113113
}
114114

115115
private func toggleAccessGroup() {
116-
if AppManager.shared.auth().userAccessGroup == nil {
117-
guard let bundleDictionary = Bundle.main.infoDictionary,
118-
let group = bundleDictionary["AppIdentifierPrefix"] as? String else {
119-
fatalError("Configure AppIdentifierPrefix in the plist")
116+
do {
117+
if AppManager.shared.auth().userAccessGroup == nil {
118+
guard let bundleDictionary = Bundle.main.infoDictionary,
119+
let group = bundleDictionary["AppIdentifierPrefix"] as? String else {
120+
fatalError("Configure AppIdentifierPrefix in the plist")
121+
}
122+
try AppManager.shared.auth().useUserAccessGroup(group +
123+
"com.google.firebase.auth.keychainGroup1")
124+
} else {
125+
try AppManager.shared.auth().useUserAccessGroup(nil)
120126
}
121-
AppManager.shared.auth().userAccessGroup = group + "com.google.firebase.auth.keychainGroup1"
122-
} else {
123-
AppManager.shared.auth().userAccessGroup = nil
127+
} catch {
128+
fatalError("Failed to set userAccessGroup with error \(error)")
124129
}
125130
}
126131

0 commit comments

Comments
 (0)