Home > Blockchain >  FirebaseAuth.instance.userChanges keeps getting called
FirebaseAuth.instance.userChanges keeps getting called

Time:07-29

In main.dart I've added this:

FirebaseAuth.instance.userChanges().listen((event) async {
      debugPrint('user state changed in main');
    });

The event is continuously getting triggered, with no changes to the users logged in status (I am developing for the web, not tested on devices).

CodePudding user response:

Use authStateChanges when interested in the current user.

authStateChanges

Notifies about changes to the user's sign-in state (such as sign-in or sign-out).

userChanges

Notifies about changes to any user updates.

CodePudding user response:

The issue was isolated - I was calling this inside the .listen((event) async {}

token = await FirebaseAuth.instance.currentUser!.getIdTokenResult(true);

which was triggering the event again...

  • Related