Flutterfire: [firebase_auth_web] authentication status not persistent

Created on 1 Feb 2020  路  12Comments  路  Source: FirebaseExtended/flutterfire

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.

crowd bug

Most helpful comment

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

All 12 comments

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

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

https://github.com/FirebaseExtended/flutterfire/issues/1771

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

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.

lgtm

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

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

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

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

any updates on this issue ?

Updates on this?

@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

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

Was this page helpful?
0 / 5 - 0 ratings