Function to create a new account. (Dart - Flutter - cloud - function)
- 1
- Flutter
- Functions
- Cloud
I am using a function to create a new user account (those that appear in the Auth section of the console) and I am doing it in dart. I created the function by selecting dart 3.1 and when it was created it did so using dart 2.17 with dart_appwrite version 8.0.0 and it did not allow me to create an account with those versions, so I had to update the dart_appwrite 11.0.2 parameters and environment: sdk: ^3.1.0 to enable me to create a new account. This is the code I am using for the function
import 'dart:async'; import 'dart:convert'; import 'package:dart_appwrite/dart_appwrite.dart';
Future<dynamic> 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
message: onError creating account account =====> type 'Null' is not a subtype of type 'bool'
I would like to know the reason for the error
Recommended threads
- Project in AppWrite Cloud doesn't allow ...
I have a collection where the data can't be opened. When I check the functions, there are three instances of a function still running that can't be deleted. The...
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Function in Node.JS to monitor events ar...
Hello everyone. I'm creating my first Node.JS function, but I don't have much experience with node and javascript. I'm trying to create a function, that monito...