loadCurrentSession method

Future<Session?> loadCurrentSession()

Implementation

Future<Session?> loadCurrentSession() {
  debug("loading current session from storage");
  return storageProvider.getSession().then((session) {
    // When loading current session initialize _session attribute
    _session = null;
    // Check if it is valid, otherwise invalidate/remove it
    if (session != null && _isSessionValid(session)) {
      _session = session;
    } else if (session != null) {
      // If we had a session stored locally but is invalid, remove it
      storageProvider.removeSession();
    }
    // Trigger session stream
    _sessionController.add(_session);
    return _session;
  });
}