createKeys function
Implementation
Future<void> createKeys() async {
final secureStorage = SecureStorageUtil();
String? accessToken = await secureStorage.getAccessToken();
if (accessToken != null) {
final response = await http.post(Uri.parse('$ipAddress/keygen'),
headers: {
'x-api-key': MoonGateConfig.apiKey,
'Content-Type': 'application/json',
},
body: jsonEncode({
"access_token": accessToken,
}));
if (response.statusCode == 200) {
// If the server returns a 200 OK response, parse the data
var data = response.body;
// Do something with the data
await secureStorage.setKeyShare(data);
} else {
// If the server returns an error response, throw an exception
throw Exception('Failed to load data from backend');
}
} else {
print('Access token not found');
}
}