Skip to content
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
1 change: 1 addition & 0 deletions FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased
- [fixed] Add a mechanism to prevent concurrent token refreshes. (#15474)
- [fixed] Fix "weak never mutated" build warning introduced in Xcode 26.2.

# 12.2.0
- [added] Added TOTP support for macOS.
Expand Down
22 changes: 11 additions & 11 deletions FirebaseAuth/Sources/Swift/Auth/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1938,30 +1938,30 @@ extension Auth: AuthInterop {
"for the new token.")
}
autoRefreshScheduled = true
weak var weakSelf = self
authDispatcher.dispatch(afterDelay: delay, queue: kAuthGlobalWorkQueue) {
guard let strongSelf = weakSelf else {
authDispatcher.dispatch(afterDelay: delay, queue: kAuthGlobalWorkQueue) { [weak self] in
guard let self else {
return
}
guard strongSelf._currentUser?.rawAccessToken() == accessToken else {
guard self._currentUser?.rawAccessToken() == accessToken else {
// Another auto refresh must have been scheduled, so keep _autoRefreshScheduled unchanged.
return
}
strongSelf.autoRefreshScheduled = false
if strongSelf.isAppInBackground {
self.autoRefreshScheduled = false
if self.isAppInBackground {
return
}
let uid = strongSelf._currentUser?.uid
strongSelf._currentUser?
.internalGetToken(forceRefresh: true, backend: strongSelf.backend) { token, error in
if strongSelf._currentUser?.uid != uid {
let uid = self._currentUser?.uid
self._currentUser?
.internalGetToken(forceRefresh: true, backend: self.backend) { [weak self] token, error in
guard let self else { return }
if self._currentUser?.uid != uid {
return
}
if error != nil {
// Kicks off exponential back off logic to retry failed attempt. Starts with one minute
// delay (60 seconds) if this is the first failed attempt.
let rescheduleDelay = retry ? min(delay * 2, 16 * 60) : 60
strongSelf.scheduleAutoTokenRefresh(withDelay: rescheduleDelay, retry: true)
self.scheduleAutoTokenRefresh(withDelay: rescheduleDelay, retry: true)
}
}
}
Expand Down
Loading