import 'dart:async';
import 'dart:convert';
import 'package:dart_appwrite/dart_appwrite.dart';
Future main(final context) async {
String message = 'error';
if (context.req.body != null &&
context.req.body != '' &&
context.req.method == 'POST') {
context
.log('entro aqui ya que viene por POST con esto ${context.req.body}');
try {
final client = Client()
.setEndpoint('https://cloud.appwrite.io/v1')
.setProject('MIPROYECTO');
final account = Account(client);
final formData = jsonDecode(context.req.body) as Map<String, dynamic>;
final email = formData['email'].toString();
final password = formData['password'].toString();
final username = formData['username'].toString();
context.log(
'estos datos llegan a la funcion $email - $password - $username');
await account
.create(
userId: ID.unique(),
email: email,
password: password,
name: username,
)
.then((value) async {
context.log('se crea la cuenta');
context.log('value = $value');
message =
'Se creo la cuenta de usuario con email: $email y password: $password';
}).catchError((onError) {
// context.log('onError al crear la cuenta account =====> $onError');
message = 'onError al crear la cuenta account =====> $onError';
});
} on AppwriteException catch (e) {
// context.log('ocurrio un error= $e');
message = e.message ?? 'error - e = $e';
}
}
context.log('message: $message');
return context.res.json({
'message': message,
});
}
I call the function from my app developed in Flutter to run and the new account is created because I can see it in the console in the Auth section but when I go to the Function Executions section in the response I see the following error