Skip to content

Refactor FirebaseUser to handle C++ objects better #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 15, 2023
Merged

Conversation

a-maurice
Copy link
Collaborator

@a-maurice a-maurice commented Aug 10, 2023

Description

Provide details of the change, and generalize the change in the PR title above.

The C++ object for FirebaseUser isn't reliable enough in memory for the C# object to hold onto a reference to it (for example, if the AuthResult is deleted, the User will be as well). Some users were seeing crashes being caused by this.
Fix it by fetching the C++ object when needed, which guarantees that it will be a valid C++ object.


Testing

Describe how you've tested these changes.

https://github.com/firebase/firebase-unity-sdk/actions/runs/5863182504


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

@a-maurice a-maurice requested a review from chkuang-g August 15, 2023 17:59
/// preset error code: kAuthErrorUnimplemented.
[System.Obsolete("Please use `Task<AuthResult> ReauthenticateWithProviderAsync(FederatedAuthProvider)` instead", false)]
public async Task<SignInResult> ReauthenticateWithProviderAsync_DEPRECATED(FederatedAuthProvider provider) {
FirebaseUserInternal userInternal = GetValidFirebaseUserInternal();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why trying to get a reference to FirebaseUserInternal here but never use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is using it, unless I'm misunderstanding what you mean.

@@ -1193,21 +1118,7 @@ static CppInstanceManager<Auth> g_auth_instances;

%typemap(csclassmodifiers) firebase::auth::Auth "public sealed class";
%typemap(csclassmodifiers) firebase::auth::User "public sealed class";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe firebase::auth::User should be internal sealed class now since we do not want to expose FirebaseUserInternal

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it was getting changed to internal by the post process thing that changes things with "Internal" in the name, but it is definitely confusing, so will change it here as well.

Comment on lines 1231 to 1236
public FirebaseUser User {
// Both FirebaseAuth.CurrentUser and AuthResult.User returns null if the
// user is invalid.
get { return (UserInternal != null && UserInternal.IsValid()) ? UserInternal : null; }
// Return the Auth's User, since there can currently only be one user per Auth.
get {
return authProxy != null ? authProxy.CurrentUser : null;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am expecting SignInResult.User would have exactly the same issue. I think we should properly fix it until we actually remove this API.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. SignInResult already does this logic, of using the authProxy and returning the User based on it instead.

@a-maurice a-maurice requested a review from chkuang-g August 15, 2023 22:38
@a-maurice a-maurice merged commit ce0466f into main Aug 15, 2023
@a-maurice a-maurice deleted the am-auth_user branch August 15, 2023 22:53
@firebase firebase locked and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants