Skip to content

Commit e5a7384

Browse files
authored
[Auth] Make two string properties atomic (#14308)
1 parent ed5ea20 commit e5a7384

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

FirebaseAuth/Sources/Swift/Auth/Auth.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,16 @@ extension Auth: AuthInterop {
23822382
private let keychainServices: AuthKeychainServices
23832383

23842384
/// The user access (ID) token used last time for posting auth state changed notification.
2385-
private var lastNotifiedUserToken: String?
2385+
///
2386+
/// - Note: The atomic wrapper can be removed when the SDK is fully
2387+
/// synchronized with structured concurrency.
2388+
private var lastNotifiedUserToken: String? {
2389+
get { lastNotifiedUserTokenLock.withLock { _lastNotifiedUserToken } }
2390+
set { lastNotifiedUserTokenLock.withLock { _lastNotifiedUserToken = newValue } }
2391+
}
2392+
2393+
private var _lastNotifiedUserToken: String?
2394+
private var lastNotifiedUserTokenLock = NSLock()
23862395

23872396
/// This flag denotes whether or not tokens should be automatically refreshed.
23882397
/// Will only be set to `true` if the another Firebase service is included (additionally to

FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,17 @@ class SecureTokenService: NSObject, NSSecureCoding {
125125
///
126126
/// This method is specifically for providing the access token to internal clients during
127127
/// deserialization and sign-in events, and should not be used to retrieve the access token by
128-
/// anyone else.
129-
var accessToken: String
128+
/// anyone else.
129+
///
130+
/// - Note: The atomic wrapper can be removed when the SDK is fully
131+
/// synchronized with structured concurrency.
132+
var accessToken: String {
133+
get { accessTokenLock.withLock { _accessToken } }
134+
set { accessTokenLock.withLock { _accessToken = newValue } }
135+
}
136+
137+
private var _accessToken: String
138+
private let accessTokenLock = NSLock()
130139

131140
/// The refresh token for the user, or `nil` if the user has yet completed sign-in flow.
132141
///
@@ -147,7 +156,7 @@ class SecureTokenService: NSObject, NSSecureCoding {
147156
refreshToken: String) {
148157
internalService = SecureTokenServiceInternal()
149158
self.requestConfiguration = requestConfiguration
150-
self.accessToken = accessToken
159+
_accessToken = accessToken
151160
self.accessTokenExpirationDate = accessTokenExpirationDate
152161
self.refreshToken = refreshToken
153162
}

0 commit comments

Comments
 (0)