Skip to content

Commit

Permalink
[Auth] Make two string properties atomic (#14308)
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 authored Jan 7, 2025
1 parent ed5ea20 commit e5a7384
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 10 additions & 1 deletion FirebaseAuth/Sources/Swift/Auth/Auth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2382,7 +2382,16 @@ extension Auth: AuthInterop {
private let keychainServices: AuthKeychainServices

/// The user access (ID) token used last time for posting auth state changed notification.
private var lastNotifiedUserToken: String?
///
/// - Note: The atomic wrapper can be removed when the SDK is fully
/// synchronized with structured concurrency.
private var lastNotifiedUserToken: String? {
get { lastNotifiedUserTokenLock.withLock { _lastNotifiedUserToken } }
set { lastNotifiedUserTokenLock.withLock { _lastNotifiedUserToken = newValue } }
}

private var _lastNotifiedUserToken: String?
private var lastNotifiedUserTokenLock = NSLock()

/// This flag denotes whether or not tokens should be automatically refreshed.
/// Will only be set to `true` if the another Firebase service is included (additionally to
Expand Down
15 changes: 12 additions & 3 deletions FirebaseAuth/Sources/Swift/SystemService/SecureTokenService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,17 @@ class SecureTokenService: NSObject, NSSecureCoding {
///
/// This method is specifically for providing the access token to internal clients during
/// deserialization and sign-in events, and should not be used to retrieve the access token by
/// anyone else.
var accessToken: String
/// anyone else.
///
/// - Note: The atomic wrapper can be removed when the SDK is fully
/// synchronized with structured concurrency.
var accessToken: String {
get { accessTokenLock.withLock { _accessToken } }
set { accessTokenLock.withLock { _accessToken = newValue } }
}

private var _accessToken: String
private let accessTokenLock = NSLock()

/// The refresh token for the user, or `nil` if the user has yet completed sign-in flow.
///
Expand All @@ -147,7 +156,7 @@ class SecureTokenService: NSObject, NSSecureCoding {
refreshToken: String) {
internalService = SecureTokenServiceInternal()
self.requestConfiguration = requestConfiguration
self.accessToken = accessToken
_accessToken = accessToken
self.accessTokenExpirationDate = accessTokenExpirationDate
self.refreshToken = refreshToken
}
Expand Down

0 comments on commit e5a7384

Please sign in to comment.