Skip to content
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

fix(firebase_auth): Move communication to EventChannels #4643

Merged
merged 34 commits into from
Apr 20, 2021

Conversation

ened
Copy link
Contributor

@ened ened commented Jan 12, 2021

Description

Similar to #4209, this PR addresses some issues rgd. isolate communication pertaining left-open "channels" to communicate back from native side to Dart.

Instead, the Flutter EventChannel mechanism is now used for the following parts:

  • ID Token Changes
  • Auth State changes
  • Phone Number verification

Related Issues

Closes #3507
Closes #4416

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

Please help testing the PR

Add the following to your pubspec.yaml:

dependency_overrides:
  firebase_auth:
    git:
      url: https://github.com/ened/flutterfire.git
      ref: fix/4416-firebase-auth
      path: packages/firebase_auth/firebase_auth
  firebase_auth_platform_interface:
    git:
      url: https://github.com/ened/flutterfire.git
      ref: fix/4416-firebase-auth
      path: packages/firebase_auth/firebase_auth_platform_interface

@google-cla google-cla bot added the cla: yes label Jan 12, 2021
@ened ened changed the title Move Firebase Auth communication to EventChannels when possible [firebase_auth] Move communication to EventChannels Jan 13, 2021
@ened ened changed the title [firebase_auth] Move communication to EventChannels fix(firebase_auth): Move communication to EventChannels Jan 13, 2021
@ened ened changed the base branch from master to no-nullsafety January 17, 2021 08:01
@ened
Copy link
Contributor Author

ened commented Apr 6, 2021

@rrousselGit @Salakar @Ehesp hi there - this PR is ready for review.

The e2e example currently fails due to the phone number being linked with another account. The same error can be observed on the master branch.

Could you spare a minute to take a look?

Copy link
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

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

A few nitpicks from me. One other thing would be to run melos run format from root as I think there is one iOS file that needs formatting. Other than that, great work again, @ened. We really appreciate it.

@@ -1377,9 +1216,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
return Tasks.call(
cachedThreadPool,
() -> {
removeEventListeners();
// TODO: not sure if this is applicable here.
// removeEventListeners();
Copy link
Member

Choose a reason for hiding this comment

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

@Salakar, will we need to clean up event listeners for didReinitializeFirebaseCore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When does didReinitializeFirebaseCore get called usually?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, when the core is reinitialized (doh!) - in the firebase core plugin. If the user changes the firebase project then we need to clean up the plugins. There is a problem in cloud_firestore as well as this PR: The didReinitializeFirebaseCore does not clear the event listeners, which may cause errors. The listeners get cleared up when the plugin is destroyed. Hm..

Sounds like a central cleanup method in the plugin would be the right way to go here.

Copy link
Member

Choose a reason for hiding this comment

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

didReinitializeFirebaseCore is also called on Dart Hot Restarts in dev (was mainly added for this purpose) - so it would be best if the event listeners are also cleaned up here otherwise these would linger in native when Dart is no longer aware of them?

'phoneNumber': phoneNumber,
'timeout': timeout.inMilliseconds,
'forceResendingToken': forceResendingToken,
'autoRetrievedSmsCodeForTesting': autoRetrievedSmsCodeForTesting,
});

EventChannel(eventChannelName!)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This StreamSubscription is not cancelled.

@google-cla
Copy link

google-cla bot commented Apr 15, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Apr 15, 2021
@Salakar
Copy link
Member

Salakar commented Apr 15, 2021

@googlebot I consent.

@google-cla google-cla bot added cla: yes and removed cla: no labels Apr 15, 2021
@ened
Copy link
Contributor Author

ened commented Apr 15, 2021

Thank you @Salakar for joining :)

@Salakar
Copy link
Member

Salakar commented Apr 15, 2021

Thank you @Salakar for joining :)

No worries, I think this is the last bit and then we're good to merge and ship;

image


The test failures re credential in use are also occurring on master so unrelated to this PR and being investigated separately.

@ened
Copy link
Contributor Author

ened commented Apr 15, 2021

Thank you @Salakar for joining :)

No worries, I think this is the last bit and then we're good to merge and ship;

image

The test failures re credential in use are also occurring on master so unrelated to this PR and being investigated separately.

OK will take care. I did not see your reply before just now.

@ened
Copy link
Contributor Author

ened commented Apr 20, 2021

@Salakar Addressed the last piece of feedback. Please also see #5852 for the similar fix in cloud_firestore.

@Salakar Salakar merged commit 8115cd5 into firebase:master Apr 20, 2021
@firebase firebase locked and limited conversation to collaborators May 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
4 participants