feat: Implement server data deletion functionality with confirmation dialog in SettingsScreen
This commit is contained in:
@@ -217,6 +217,35 @@ class AuthApi {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> deleteAllServerData({String? endpoint}) async {
|
||||
final String? token = await accessToken;
|
||||
if (token == null) {
|
||||
return {'error': true, 'message': 'No access token available'};
|
||||
}
|
||||
|
||||
final String base = endpoint ?? await ApiConfig.getEndpoint();
|
||||
final Uri url = Uri.parse('$base/auth/delete-all-data');
|
||||
|
||||
final http.Response res = await http.post(
|
||||
url,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
return {'error': false, 'status': res.statusCode, 'body': res.body};
|
||||
}
|
||||
|
||||
try {
|
||||
final dynamic decoded = jsonDecode(res.body);
|
||||
return {'error': true, 'status': res.statusCode, 'body': decoded};
|
||||
} catch (_) {
|
||||
return {'error': true, 'status': res.statusCode, 'body': res.body};
|
||||
}
|
||||
}
|
||||
|
||||
List<int> _randomBytes(int length) {
|
||||
final Random random = Random.secure();
|
||||
return List<int>.generate(length, (_) => random.nextInt(256));
|
||||
|
||||
Reference in New Issue
Block a user