wpLogout method
Logs out the user. Sends a request to revoke the token on the server, then removes the user and token from the device.
The local session is always cleared, even if the request fails (e.g. the token has already expired or there is no connection).
Returns true if the server revoked the token, false otherwise.
Implementation
Future<bool> wpLogout({String? userToken}) async {
bool revoked = false;
try {
String? token = userToken ?? await WPJsonAPI.wpUserToken();
if (token != null && token.isNotEmpty) {
await _http(
method: "POST",
url: _urlForRouteType(WPRouteType.UserLogout),
userToken: token,
shouldAuthRequest: true,
);
revoked = true;
}
} on Exception catch (e) {
_devLogger(
url: _urlForRouteType(WPRouteType.UserLogout),
result: "Logout request failed, clearing the local session: $e");
} finally {
await WPJsonAPI.wpLogout();
}
return revoked;
}