feat: Implement server data deletion functionality with confirmation dialog in SettingsScreen

This commit is contained in:
2026-05-20 17:33:22 +02:00
parent 3ff4efb738
commit 2ef9cf1dbb
2 changed files with 138 additions and 16 deletions
+29
View File
@@ -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));