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

[firebase_auth_web] authentication status not persistent #1918

Closed
tianhaoz95 opened this issue Feb 1, 2020 · 12 comments
Closed

[firebase_auth_web] authentication status not persistent #1918

tianhaoz95 opened this issue Feb 1, 2020 · 12 comments
Assignees
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) type: bug Something isn't working

Comments

@tianhaoz95
Copy link

tianhaoz95 commented Feb 1, 2020

Describe the bug

According to firebase auth doc, the default behavior of firebase auth persistency is LOCAL meaning it should persistent across refresh. However, that's not the case with firebase_auth_web.

Setting the persistency manually did help either:

https://github.com/tianhaoz95/iwfp/blob/faaabf9788fc393888a66a7b864e582fca4b8952/iwfpapp/web/index.html#L12-L26

To Reproduce

Steps to reproduce the behavior:

  1. setup firebase_auth for web app
  2. sign in
  3. refresh the browser
  4. user is signed out

Expected behavior

Users should still be signed in after refreshing the tab.

Additional context

Fun fact: it persists during development, but not when the app is compiled.

@tianhaoz95 tianhaoz95 added the type: bug Something isn't working label Feb 1, 2020
@Luis-Barba
Copy link

I have found the solution:
Instead of this:
await _firebaseAuth.currentUser();
use this:
await _firebaseAuth.onAuthStateChanged.first;

@iapicca iapicca added blocked: customer-response Waiting for customer response, e.g. more information was requested. impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) labels Mar 6, 2020
@iapicca
Copy link

iapicca commented Mar 6, 2020

Hi @tianhaoz95
does the proposed solution works for you?
If doesn't can you please provide
your flutter doctor -v ,
your flutter run --verbose
and your pubspec.yaml
or if possible a reproducible minimal code sample.
Thank you

#1771

@tianhaoz95
Copy link
Author

@iapicca yes it worked for me. You can probably mark as fixed if that is the suggested approach.

@slightfoot
Copy link
Contributor

This is a bug if the implementations of the platform interfaces have different results.

Just checked and the JavaScript SDK treats it as a property: https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/auth.js#L928

I think we should update the getCurrentUser function to track the initialization and use the fix above to wait for the first authChanged response whilst the library is still initializing.

@tianhaoz95
Copy link
Author

lgtm

@iapicca iapicca removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Mar 8, 2020
@tianhaoz95
Copy link
Author

@iapicca what is left in this issue? Do we want to use it as a tracking bug for the JS SDK fix?

@iapicca
Copy link

iapicca commented Mar 11, 2020

Hi @tianhaoz95
I think you are right, thanks for letting me know

@slightfoot is it ok for you if I close this?

@slightfoot
Copy link
Contributor

This fix cannot be put in the JS SDK. Assign this ticket to me.

@Yacine-Benali
Copy link

any updates on this issue ?

@joaquini
Copy link

Updates on this?

@nilsreichardt
Copy link
Contributor

@joaquini Maybe this is fixed with 0.18.0 , because they made a complete rework of firebase_auth. Have tried it with the new version?

https://pub.dev/packages/firebase_auth/changelog

@Salakar
Copy link
Member

Salakar commented Aug 25, 2020

Hey 👋

The rework of the firebase_auth plugin as part of the FlutterFire roadmap was published over a week ago with a ton of fixes and new features. Please could you try the new version and see if this is still an issue for you? If it is then please submit a new up to date GitHub issue.

We also added support on web for configuring persistence, see: https://firebase.flutter.dev/docs/auth/usage#persisting-authentication-state

For help migrating to the new plugins please see the new migration guide: https://firebase.flutter.dev/docs/migration

@Salakar Salakar closed this as completed Aug 25, 2020
@firebase firebase locked and limited conversation to collaborators Sep 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: crowd Affects many people, though not necessarily a specific customer with an assigned label. (P2) type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants