@@ -616,8 +616,6 @@ static CppInstanceManager<Auth> g_auth_instances;
616
616
private System.IntPtr authStateListener;
617
617
// Pointer to IdTokenListenerImpl.
618
618
private System.IntPtr idTokenListener;
619
- // Proxy for the current user object.
620
- private FirebaseUser currentUser;
621
619
622
620
// Retrieve a reference to the auth object associated with the specified app.
623
621
private static FirebaseAuth ProxyFromAppCPtr (System.IntPtr appCPtr) {
@@ -690,16 +688,6 @@ static CppInstanceManager<Auth> g_auth_instances;
690
688
appProxy = null;
691
689
appCPtr = System.IntPtr .Zero ;
692
690
693
- // Detatch the user proxy from the C++ object as it will no longer
694
- // be valid. FirebaseUser never owns the C++ object and so will never
695
- // delete it.
696
- // NOTE: This uses the cached currentUser as the auth object may be
697
- // destroyed at this point.
698
- if (currentUser != null) {
699
- currentUser.Dispose ();
700
- currentUser = null;
701
- }
702
-
703
691
// Destroy token and auth state listeners.
704
692
if (authStateListener != System.IntPtr .Zero ) {
705
693
AuthUtil.DestroyAuthStateListener (this , authStateListener);
@@ -734,9 +722,6 @@ static CppInstanceManager<Auth> g_auth_instances;
734
722
ForwardStateChange (appCPtr, (auth) => {
735
723
// If any state changed events are registered, signal them.
736
724
if (auth.stateChangedImpl != null) {
737
- lock (appCPtrToAuth) {
738
- auth.UpdateCurrentUser (auth.CurrentUserInternal );
739
- }
740
725
auth.stateChangedImpl (auth, System.EventArgs .Empty );
741
726
}
742
727
@@ -877,25 +862,17 @@ static CppInstanceManager<Auth> g_auth_instances;
877
862
return taskCompletionSource.Task ;
878
863
}
879
864
880
- // Update the cached user proxy for this object.
881
- private FirebaseUser UpdateCurrentUser (FirebaseUser proxy) {
882
- lock (appCPtrToAuth) {
883
- if (proxy == null || !proxy.IsValid ()) {
884
- // If there is no current user, remove the cached proxy.
885
- currentUser = null;
886
- } else if (currentUser == null || !currentUser.IsValid ()) {
887
- // If no proxy is cached, cache the current proxy.
888
- currentUser = proxy;
889
- } else {
890
- // If the user changed, update the cached proxy.
891
- if (!currentUser.EqualToInternal (proxy)) {
892
- currentUser.Dispose ();
893
- currentUser = proxy;
894
- }
865
+ // Does additional work to set up the FirebaseUser.
866
+ private FirebaseUser SetupUser (FirebaseUser user) {
867
+ if (user != null) {
868
+ // If the user isn't valid, switch to use null instead
869
+ if (!user.IsValid ()) {
870
+ return null;
895
871
}
896
- if (currentUser != null) currentUser.authProxy = this ;
872
+ // Set the Auth object in the user
873
+ user.authProxy = this ;
897
874
}
898
- return currentUser ;
875
+ return user ;
899
876
}
900
877
901
878
// / @brief Synchronously gets the cached current user, or null if there is none.
@@ -905,7 +882,7 @@ static CppInstanceManager<Auth> g_auth_instances;
905
882
public FirebaseUser CurrentUser {
906
883
get {
907
884
var user = swigCPtr.Handle != System.IntPtr .Zero ? CurrentUserInternal : null;
908
- return UpdateCurrentUser (user);
885
+ return SetupUser (user);
909
886
}
910
887
}
911
888
@@ -1160,7 +1137,7 @@ static CppInstanceManager<Auth> g_auth_instances;
1160
1137
Firebase.Internal .TaskCompletionSourceCompat <FirebaseUser>.SetException (
1161
1138
taskCompletionSource, task.Exception );
1162
1139
} else {
1163
- taskCompletionSource.SetResult (UpdateCurrentUser (task.Result ));
1140
+ taskCompletionSource.SetResult (SetupUser (task.Result ));
1164
1141
}
1165
1142
}
1166
1143
@@ -1195,7 +1172,7 @@ static CppInstanceManager<Auth> g_auth_instances;
1195
1172
AuthResult result = task.Result ;
1196
1173
// This assume all the users from AuthResult points to current users.
1197
1174
// TODO(AuthRewrite): Update this logic when we can have multile FirebaseUser.
1198
- result.UserInternal = UpdateCurrentUser (result.User );
1175
+ result.UserInternal = SetupUser (result.User );
1199
1176
taskCompletionSource.SetResult (result);
1200
1177
}
1201
1178
}
@@ -1314,7 +1291,7 @@ static CppInstanceManager<Auth> g_auth_instances;
1314
1291
1315
1292
// / The currently signed-in FirebaseUser, or null if there isn't any (i.e.
1316
1293
// / the user is signed out).
1317
- public FirebaseUser User { get { return authProxy.CurrentUser ; } }
1294
+ public FirebaseUser User { get { return authProxy != null ? authProxy .CurrentUser : null ; } }
1318
1295
%}
1319
1296
1320
1297
// AuthResult
0 commit comments