logout method
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.
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);
}