signOut method
If an input token is provided, signs out the user from the current session, clears user and session data in local storage and removes the Session header in Fetcher. Otherwise, signs out the user from the session identified by the input token.
An active user session is required (e.g., user needs to be logged in) to call this method.
sessionToken
Session token which uniquely identifies a user session.
Implementation
Future<APIError?> signOut([String? sessionToken]) async {
try {
var response = await _fetcher.post<dynamic>('/_api/rest/v1/auth/signout',
body: {if (sessionToken != null) 'token': sessionToken});
var session = await getSession();
if (response.errors == null &&
(sessionToken == null ||
(session != null && sessionToken == session.token))) {
await _deleteLocalData();
_fetcher.clearSession();
}
return response.errors;
} on Exception {
return null;
}
}