userChanges property
Stream of AuthUser
which will emit the current user when
the authentication state changes.
This stream will also emit when the user is signed out.
Emits AuthUser.empty if the user is not authenticated.
Implementation
Stream<AuthUser> get userChanges async* {
_firebaseAuth.userChanges().asyncMap((firebaseUser) async* {
final authToken = await firebaseUser?.getIdToken(true);
final user = firebaseUser == null
? AuthUser.empty
: firebaseUser.toUser.copyWith(authToken: authToken);
_cache.write(key: userCacheKey, value: user);
yield user;
});
}