checkAuthentication method

Future<void> checkAuthentication()

Implementation

Future<void> checkAuthentication() async {
  if (_action != _LoginAction.none) {
    throw StateError("There is already a login or logout action in progress");
  }

  _action = _LoginAction.checkAuthentication;
  _status = LoginStatus.pending;
  _token = null;
  _error = null;
  notifyListeners();

  try {
    if (await helper.isAuthenticated()) {
      _token = await helper.getTokenFromStorage();
      _status = LoginStatus.loggedIn;
    } else {
      _status = LoginStatus.loggedOut;
    }
    _action = _LoginAction.none;
    notifyListeners();
  } catch (e) {
    _error = e;
    _status = LoginStatus.error;
    _action = _LoginAction.none;
    notifyListeners();
    rethrow;
  }
}