skip to Main Content

I have a Flutter web app with accompanying iOS app – all in Flutter, and I am using Firebase auth.

I am listening to changes on the user with FirebaseAuth.instance.userChanges()

If I log in with a single device (web) and update the display name on the user, userChanges stream is triggered just fine.

But if I log in on both devices (web and mobile) with the same user, and change the display name on one device, only the device on which I make the change receives a Firebase userChanges notification.

I have checked and all subscriptions to the streams are live.

Why is Firebase only notifying one device?

Ps. I know a user using two devices at once is fringe case, but it is a possible scenario.

2

Answers


  1. userChanges will not trigger immediately in response to changes in the properties of the user object. According to the documentation:

    Warning: idTokenChanges(), userChanges() & authStateChanges() will not fire if you update the User profile via your own firebase admin sdk implementation. You will have to force a reload using the following FirebaseAuth.instance.currentUser.reload() to retrieve the latest User profile.

    If you need realtime updates of user data, then you probably shouldn’t depend on Firebase Auth for that, unless you are comfortable reloading frequently. (Firebase Auth isn’t really a database and you shouldn’t treat it like one.) Instead, store the data in a database, and query that for changes. If you’re using Firebase Realtime Database or Firestore, you can even listen do a node or document in the database to get changes in real time when another client or your backend makes updates.

    Login or Signup to reply.
  2. All information about the current user is kept in the ID token that the Firebase SDK gets from the server when the user signs in. Once the user is signed in, the ID token is refreshed from the server oncer per hour or when there is a change in the local client.

    So the client that makes the change sees it right away, but any other client will have to wait up to an hour before it gets an updated ID token with that change.

    If you want the other clients to see the change before, you can reload their profile.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search