Skip to content

Commit 8bf009c

Browse files
authored
[Auth] Reduce callback nesting (#15079)
1 parent 2d6056a commit 8bf009c

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

FirebaseAuth/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- [changed] **Breaking Change**: `TOTPSecret.openInOTPApp(withQRCodeURL:)` is
1111
now labeled with `@MainActor` and requires the `await` keyword when called
1212
off of the main actor or main thread.
13+
- [fixed] Simplified completion handler memory management in Auth interop
14+
(#14962).
1315

1416
# 11.15.0
1517
- [fixed] Fixed `Sendable` warnings introduced in the Xcode 26 beta. (#14996)

FirebaseAuth/Sources/Swift/Auth/Auth.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ extension Auth: AuthInterop {
124124
}
125125
// Call back with current user token.
126126
currentUser
127-
.internalGetToken(forceRefresh: forceRefresh, backend: strongSelf.backend) { token, error in
128-
DispatchQueue.main.async {
129-
callback(token, error)
130-
}
131-
}
127+
.internalGetToken(
128+
forceRefresh: forceRefresh,
129+
backend: strongSelf.backend,
130+
callback: callback,
131+
callCallbackOnMain: true
132+
)
132133
}
133134
}
134135

FirebaseAuth/Sources/Swift/User/User.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,13 +1591,22 @@ extension User: NSSecureCoding {}
15911591
/// on the global work thread in the future.
15921592
func internalGetToken(forceRefresh: Bool = false,
15931593
backend: AuthBackend,
1594-
callback: @escaping (String?, Error?) -> Void) {
1594+
callback: @escaping (String?, Error?) -> Void,
1595+
callCallbackOnMain: Bool = false) {
15951596
Task {
15961597
do {
15971598
let token = try await internalGetTokenAsync(forceRefresh: forceRefresh, backend: backend)
1598-
callback(token, nil)
1599+
if callCallbackOnMain {
1600+
Auth.wrapMainAsync(callback: callback, with: .success(token))
1601+
} else {
1602+
callback(token, nil)
1603+
}
15991604
} catch {
1600-
callback(nil, error)
1605+
if callCallbackOnMain {
1606+
Auth.wrapMainAsync(callback: callback, with: .failure(error))
1607+
} else {
1608+
callback(nil, error)
1609+
}
16011610
}
16021611
}
16031612
}

0 commit comments

Comments
 (0)