logout method

Future<AuthResponse> logout({
  1. bool all = false,
})

Logs out the current user.

If all is true, all of the user's devices will be logged out.

Returns an AuthResponse with its fields unset.

Throws an ApiException if logout fails.

https://docs.nhost.io/auth/api-reference#logout-user

Implementation

Future<AuthResponse> logout({
  bool all = false,
}) async {
  log.finer('Attempting logout');
  final refreshToken =
      await _authStore.getString(refreshTokenClientStorageKey);
  try {
    await _apiClient.post(
      '/logout',
      query: {
        'refresh_token': refreshToken,
      },
      data: {
        'all': all,
      },
    );
    log.finer('Logout successful');
  } catch (e, st) {
    log.finer('Logout failed', e, st);

    // noop
    // TODO(shyndman): This probably shouldn't be a noop. If a logout fails,
    // particularly in the ?all=true case, the user should know about it
  }

  await _clearSession();
  return AuthResponse(session: null, user: null);
}