deleteUser method
This method can delete a user in one of 2 situations: the first is an authenticated deleting themselves (do not provide userID
). The second is an admin deleting a user using an admin token. When a userID
, the method will assume the instance token has Admin access.
Implementation
Future<void> deleteUser({String? userID}) async {
String? token;
if (userID != null)
token = instance.token;
else {
token = getAccessToken();
userID = _getUserID();
}
if (token == null || userID == null)
throw ("UserID not provided, a user must be authenticated or userID provided");
Options options = Options(
headers: {'Authorization': 'Bearer $token', "Accept-Version": "v1"});
String url = '$authEndpoint/user/$userID';
try {
await Dio().delete(url, options: options);
return _logout();
} catch (err) {
if (err is DioException) throw (err.response.toString());
}
return;
}