@@ -116,7 +116,7 @@ extension Auth: AuthInterop {
116
116
}
117
117
}
118
118
// Call back with 'nil' if there is no current user.
119
- guard let strongSelf = self , let currentUser = strongSelf. currentUser else {
119
+ guard let strongSelf = self , let currentUser = strongSelf. _currentUser else {
120
120
DispatchQueue . main. async {
121
121
callback ( nil , nil )
122
122
}
@@ -136,7 +136,7 @@ extension Auth: AuthInterop {
136
136
///
137
137
/// This method is not for public use. It is for Firebase clients of AuthInterop.
138
138
open func getUserID( ) -> String ? {
139
- return currentUser ? . uid
139
+ return _currentUser ? . uid
140
140
}
141
141
}
142
142
@@ -170,7 +170,13 @@ extension Auth: AuthInterop {
170
170
@objc public internal( set) weak var app : FirebaseApp ?
171
171
172
172
/// Synchronously gets the cached current user, or null if there is none.
173
- @objc public internal( set) var currentUser : User ?
173
+ @objc public var currentUser : User ? {
174
+ kAuthGlobalWorkQueue. sync {
175
+ _currentUser
176
+ }
177
+ }
178
+
179
+ private var _currentUser : User ?
174
180
175
181
/// The current user language code.
176
182
///
@@ -702,7 +708,7 @@ extension Auth: AuthInterop {
702
708
@objc open func signInAnonymously( completion: ( ( AuthDataResult ? , Error ? ) -> Void ) ? = nil ) {
703
709
kAuthGlobalWorkQueue. async {
704
710
let decoratedCallback = self . signInFlowAuthDataResultCallback ( byDecorating: completion)
705
- if let currentUser = self . currentUser , currentUser. isAnonymous {
711
+ if let currentUser = self . _currentUser , currentUser. isAnonymous {
706
712
let result = AuthDataResult ( withUser: currentUser, additionalUserInfo: nil )
707
713
decoratedCallback ( result, nil )
708
714
return
@@ -1264,7 +1270,7 @@ extension Auth: AuthInterop {
1264
1270
/// dictionary will contain more information about the error encountered.
1265
1271
@objc ( signOut: ) open func signOut( ) throws {
1266
1272
try kAuthGlobalWorkQueue. sync {
1267
- guard self . currentUser != nil else {
1273
+ guard self . _currentUser != nil else {
1268
1274
return
1269
1275
}
1270
1276
return try self . updateCurrentUser ( nil , byForce: false , savingToDisk: true )
@@ -1385,14 +1391,14 @@ extension Auth: AuthInterop {
1385
1391
queue: OperationQueue . main
1386
1392
) { notification in
1387
1393
if let auth = notification. object as? Auth {
1388
- listener ( auth, auth. currentUser )
1394
+ listener ( auth, auth. _currentUser )
1389
1395
}
1390
1396
}
1391
1397
objc_sync_enter ( Auth . self)
1392
1398
listenerHandles. add ( listener)
1393
1399
objc_sync_exit ( Auth . self)
1394
1400
DispatchQueue . main. async {
1395
- listener ( self , self . currentUser )
1401
+ listener ( self , self . _currentUser )
1396
1402
}
1397
1403
return handle
1398
1404
}
@@ -1434,7 +1440,7 @@ extension Auth: AuthInterop {
1434
1440
/// complete, or fails. Invoked asynchronously on the main thread in the future.
1435
1441
@objc open func revokeToken( withAuthorizationCode authorizationCode: String ,
1436
1442
completion: ( ( Error ? ) -> Void ) ? = nil ) {
1437
- currentUser ? . internalGetToken ( backend: backend) { idToken, error in
1443
+ _currentUser ? . internalGetToken ( backend: backend) { idToken, error in
1438
1444
if let error {
1439
1445
Auth . wrapMainAsync ( completion, error)
1440
1446
return
@@ -1790,7 +1796,7 @@ extension Auth: AuthInterop {
1790
1796
}
1791
1797
1792
1798
func updateKeychain( withUser user: User ? ) -> Error ? {
1793
- if user != currentUser {
1799
+ if user != _currentUser {
1794
1800
// No-op if the user is no longer signed in. This is not considered an error as we don't check
1795
1801
// whether the user is still current on other callbacks of user operations either.
1796
1802
return nil
@@ -1836,7 +1842,7 @@ extension Auth: AuthInterop {
1836
1842
}
1837
1843
1838
1844
func signOutByForce( withUserID userID: String ) throws {
1839
- guard currentUser ? . uid == userID else {
1845
+ guard _currentUser ? . uid == userID else {
1840
1846
return
1841
1847
}
1842
1848
try updateCurrentUser ( nil , byForce: true , savingToDisk: true )
@@ -1846,7 +1852,7 @@ extension Auth: AuthInterop {
1846
1852
1847
1853
/// Posts the auth state change notification if current user's token has been changed.
1848
1854
private func possiblyPostAuthStateChangeNotification( ) {
1849
- let token = currentUser ? . rawAccessToken ( )
1855
+ let token = _currentUser ? . rawAccessToken ( )
1850
1856
if lastNotifiedUserToken == token ||
1851
1857
( token != nil && lastNotifiedUserToken == token) {
1852
1858
return
@@ -1863,7 +1869,7 @@ extension Auth: AuthInterop {
1863
1869
if let token, token. count > 0 {
1864
1870
internalNotificationParameters [ FIRAuthStateDidChangeInternalNotificationTokenKey] = token
1865
1871
}
1866
- internalNotificationParameters [ FIRAuthStateDidChangeInternalNotificationUIDKey] = currentUser ?
1872
+ internalNotificationParameters [ FIRAuthStateDidChangeInternalNotificationUIDKey] = _currentUser ?
1867
1873
. uid
1868
1874
let notifications = NotificationCenter . default
1869
1875
DispatchQueue . main. async {
@@ -1880,7 +1886,7 @@ extension Auth: AuthInterop {
1880
1886
/// If the token expires in less than 5 minutes, schedule the token refresh immediately.
1881
1887
private func scheduleAutoTokenRefresh( ) {
1882
1888
let tokenExpirationInterval =
1883
- ( currentUser ? . accessTokenExpirationDate ( ) ? . timeIntervalSinceNow ?? 0 ) - 5 * 60
1889
+ ( _currentUser ? . accessTokenExpirationDate ( ) ? . timeIntervalSinceNow ?? 0 ) - 5 * 60
1884
1890
scheduleAutoTokenRefresh ( withDelay: max ( tokenExpirationInterval, 0 ) , retry: false )
1885
1891
}
1886
1892
@@ -1889,7 +1895,7 @@ extension Auth: AuthInterop {
1889
1895
/// to be executed.
1890
1896
/// - Parameter retry: Flag to determine whether the invocation is a retry attempt or not.
1891
1897
private func scheduleAutoTokenRefresh( withDelay delay: TimeInterval , retry: Bool ) {
1892
- guard let accessToken = currentUser ? . rawAccessToken ( ) else {
1898
+ guard let accessToken = _currentUser ? . rawAccessToken ( ) else {
1893
1899
return
1894
1900
}
1895
1901
let intDelay = Int ( ceil ( delay) )
@@ -1908,18 +1914,18 @@ extension Auth: AuthInterop {
1908
1914
guard let strongSelf = weakSelf else {
1909
1915
return
1910
1916
}
1911
- guard strongSelf. currentUser ? . rawAccessToken ( ) == accessToken else {
1917
+ guard strongSelf. _currentUser ? . rawAccessToken ( ) == accessToken else {
1912
1918
// Another auto refresh must have been scheduled, so keep _autoRefreshScheduled unchanged.
1913
1919
return
1914
1920
}
1915
1921
strongSelf. autoRefreshScheduled = false
1916
1922
if strongSelf. isAppInBackground {
1917
1923
return
1918
1924
}
1919
- let uid = strongSelf. currentUser ? . uid
1920
- strongSelf. currentUser ?
1925
+ let uid = strongSelf. _currentUser ? . uid
1926
+ strongSelf. _currentUser ?
1921
1927
. internalGetToken ( forceRefresh: true , backend: strongSelf. backend) { token, error in
1922
- if strongSelf. currentUser ? . uid != uid {
1928
+ if strongSelf. _currentUser ? . uid != uid {
1923
1929
return
1924
1930
}
1925
1931
if error != nil {
@@ -1943,7 +1949,7 @@ extension Auth: AuthInterop {
1943
1949
/// - Parameter saveToDisk: Indicates the method should persist the user data to disk.
1944
1950
func updateCurrentUser( _ user: User ? , byForce force: Bool ,
1945
1951
savingToDisk saveToDisk: Bool ) throws {
1946
- if user == currentUser {
1952
+ if user == _currentUser {
1947
1953
possiblyPostAuthStateChangeNotification ( )
1948
1954
}
1949
1955
if let user {
@@ -1960,7 +1966,7 @@ extension Auth: AuthInterop {
1960
1966
}
1961
1967
}
1962
1968
if throwError == nil || force {
1963
- currentUser = user
1969
+ _currentUser = user
1964
1970
possiblyPostAuthStateChangeNotification ( )
1965
1971
}
1966
1972
if let throwError {
0 commit comments