currentUserAsync property

FutureOr<User> currentUserAsync

If currentUser is not null, returns currentUser, otherwise returns Future<User> that will complete with the next User after sign-in succeeds.

Will never return null.

Implementation

FutureOr<User> get currentUserAsync {
  final current = currentUser;
  if (current != null) {
    return current;
  }

  if (_currentUserAsyncCompleter == null) {
    _currentUserAsyncCompleter = Completer<User>();
    final authStateChangedSub = onAuthStateChanged.listen(_authStateChanged);
    _currentUserAsyncCompleter!.future.then(
      (_) => authStateChangedSub.cancel(),
    );
  }

  return _currentUserAsyncCompleter!.future;
}