logOut method

Future<void> logOut()

Log the current user out. The current user value will be set to null.

Implementation

Future<void> logOut() async {
  final currentUserValue = this.currentUserValue;
  if (currentUserValue == null) return Future.value(null);

  if (_logInFuture != null) await _logInFuture;
  if (_tokenFuture != null) await _tokenFuture;

  for (final callback in _onLogoutUseCases.toList()) {
    try {
      await callback.call(currentUserValue);
    } catch (e) {
      // ignore: avoid_print
      print('Error while performing onLogout call:\n$e');

      // Continue on error.
      // Callbacks are not as important as successfully logging out
    }
  }

  _logOutFuture ??= client.logOut(currentUserValue).whenComplete(() {
    persistence.setCurrentUser(null);
    _logOutFuture = null;
  });

  return _logOutFuture!;
}