logout method

  1. @override
Future<void> logout()
override

End the session.

Every step is attempted, whatever the earlier ones did, and the first failure is rethrown at the end. Vault deletes throw on a platform error, and running these in sequence without that meant a locked keychain on the first delete left the cached user on disk, left the user in memory, and never bumped stateNotifier, so the app went on rendering a signed-in session while the caller was told the logout had failed.

The in-memory clear is last and unconditional on purpose: it is the part that cannot fail, so it is the part that must not be skipped. The throw still reaches the caller, because a logout that could not remove a credential is not a logout, and only the caller can decide what to say about it.

Implementation

@override
Future<void> logout() async {
  Object? failure;
  StackTrace? failureStack;

  try {
    await clearTokens();
  } catch (e, stack) {
    failure = e;
    failureStack = stack;
  }

  try {
    await clearUserCache();
  } catch (e, stack) {
    failure ??= e;
    failureStack ??= stack;
  }

  _user = null;
  stateNotifier.value++;

  if (failure != null) Error.throwWithStackTrace(failure, failureStack!);
}