Skip to content

firebase_auth onAuthStateChanged not updated on linkWithCredential #2690

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

Closed
erf opened this issue Jun 3, 2020 · 12 comments
Closed

firebase_auth onAuthStateChanged not updated on linkWithCredential #2690

erf opened this issue Jun 3, 2020 · 12 comments
Labels
plugin: auth type: documentation Improvements or additions to documentation

Comments

@erf
Copy link

erf commented Jun 3, 2020

Describe the bug
I'm linking an Anonymous firebaseUser to a Phone provider using firebaseUser.linkWithCredential but onAuthStateChanged is not triggered, even if i call firebaseUser.reload().

To Reproduce
Steps to reproduce the behavior:

  1. Sign in with an anonymous user
  2. Link to a phone provider using linkWithCredential

Expected behavior
I would expect Firebase.instance.onAuthStateChanged to be triggered with a new event, especially after calling firebaseUser.reload.

Additional context

Flutter doctor
Run flutter doctor and paste the output below:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.1, on Mac OS X 10.15.4 19E287, locale en-GB)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.40.0)
[✓] Connected device (1 available)

• No issues found!
@erf erf changed the title firebase_auth onAuthStateChanged is not update on firebaseUser.linkWithCredential firebase_auth onAuthStateChanged not updated on linkWithCredential Jun 3, 2020
@TahaTesser
Copy link

Hi @erf
Does this look similar to #2344?

@TahaTesser TahaTesser added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 3, 2020
@erf
Copy link
Author

erf commented Jun 3, 2020

@TahaTesser I am able to link an anonymous user to a phone provider, but the FirebaseAuth.instance.onAuthStateChanged was not called.

..but after some more testing, i think the problem is related to CombineLatestStream of rxdart, in that it does not push a new event when onAuthStateChanged does.

I'll close this for now, but if you have any experience with this scenario, please help.

Thank you.

@erf erf closed this as completed Jun 3, 2020
@erf
Copy link
Author

erf commented Jun 3, 2020

@TahaTesser Actually it does seem somewhat random, like he mentions in #2434

I removed the use of CombineLatestStream and used a regular StreamBuilder. I then call firebaseUser.unlinkFromProvider on all providers in providerData and call reload.

I don't get a new onAuthStateChanged event.

@erf erf reopened this Jun 3, 2020
@erf
Copy link
Author

erf commented Jun 3, 2020

I think this is related to #717

@TahaTesser TahaTesser removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 8, 2020
@TahaTesser
Copy link

Hi @erf
Can you please provide Your flutter run --verbose and a minimal complete reproducible code sample.
Thank you

@TahaTesser TahaTesser added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Jun 8, 2020
@erf
Copy link
Author

erf commented Jun 8, 2020

@TahaTesser that could make quite the complex example

Could you tell me if the following:

firebaseUser.linkWithCredential
firebaseUser.reload().

is supposed to trigger an event in FirebaseAuth.instance.onAuthStateChanged with a FirebaseUser with updated providerData ?

If not, then i guess everything is fine. Except i think this is what should happen.

I started using firebase_user_stream which solved my issue.

@TahaTesser TahaTesser added plugin: auth type: documentation Improvements or additions to documentation and removed blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Jun 9, 2020
@RWOverdijk
Copy link

I know this repo is not for the firebase JS web sdk, but I have the same issue there. I'm signed in as an anonymous user and upon linking with a credential it does not trigger the onAuthStateChanged.

Normally I wouldn't comment on an unrelated repo but I think these issues might be related somehow. .reload() also doesn't do anything for me so that also seems the same.

@Ehesp
Copy link
Member

Ehesp commented Jun 30, 2020

Reload doesn't retrigger anything, you should be able to call reload and access the currentUser after it.

@RWOverdijk
Copy link

I get that, I was talking about triggering the auth state change.

@bulwinkel
Copy link

For other who end up here, based on comments in this issue #717 there will be userChanges stream available in a future release of firebase_auth as part of the work being done in #2582 but it is unclear in which release it will become available.

@schankam
Copy link

I'm having the same problem after linking an anonymous user with an other provider, the onAuthStateChanged is not triggered. I am using a StreamProvider with FirebaseUser, and was expecting it to be triggered so my UI is refreshed accordingly (currently using a Visibility Widget to display extra option with the firebaseUser.isAnonymous property). If this is not working correctly, how are we supposed to rely on that boolean ?

@erf
Copy link
Author

erf commented Aug 19, 2020

I believe this is solved in firebase_auth 0.18.0. You can now listen to the userChanges stream for these events.

@erf erf closed this as completed Aug 19, 2020
@firebase firebase locked and limited conversation to collaborators Sep 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: auth type: documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

6 participants