signOut method

Future<void> signOut()

Signs out locally and attempts to invalidate the remote Laravel session.

The local session is always cleared, even when the remote logout endpoint fails due to network issues.

Implementation

Future<void> signOut() async {
  await _ensureInitialized();

  Object? remoteError;

  if (_currentSession != null) {
    try {
      await http.post(
        config.logoutPathPost,
        withAuth: true,
      );
    } catch (error) {
      remoteError = error;
    }
  }

  await _clearLocalSession(
    emitEvents: true,
  );

  if (remoteError is HosteDayException) {
    throw HosteDayAuthException.fromHosteDayException(remoteError);
  }

  if (remoteError != null) {
    throw remoteError;
  }
}