Whenever I try to await the creation of a new user using account.create() function of the flutter SDK , my async function just gets stuck at the await statement and does not proceed past it. When I check the appwrite console to see if the user was created or not I find that a new user was also not created. But if I just convert my function into a simple synchronous function and call the account.create() method without waiting for the response, my function completes execution (which it should as I am not awaiting for the response) and a new user is also created which can be seen on the appwrite console. Any suggestions to why I am facing this?
Working code snippet:
void register({
required String username,
required String password,
}) {
try {
_logger.log(Level.INFO, "Register method called of Authentication Repo.");
_logger.log(Level.INFO, "$_client");
_logger.log(Level.INFO, "$_account");
final user = _account.create(
userId: ID.unique(), email: username, password: password);
_logger.log(Level.INFO, "Reached here");
//_controller.add(AuthenticationStatus.authenticated);
} on AppwriteException {
} catch (e) {
_logger.log(Level.SEVERE, "$e");
} finally {}
}
Execution Log:
I/flutter (26475): INFO: 2023-04-15 10:59:42.667754: Register method called of Authentication Repo.
I/flutter (26475): INFO: 2023-04-15 10:59:42.668095: Instance of 'ClientIO'
I/flutter (26475): INFO: 2023-04-15 10:59:42.668442: Instance of 'Account'
I/flutter (26475): INFO: 2023-04-15 10:59:42.703901: Reached here
Non-Working code snippet:
Future<void> register({
required String username,
required String password,
}) async {
try {
_logger.log(Level.INFO, "Register method called of Authentication Repo.");
_logger.log(Level.INFO, "$_client");
_logger.log(Level.INFO, "$_account");
final user = await _account.create(
userId: ID.unique(), email: username, password: password);
_logger.log(Level.INFO, "Reached here");
//_controller.add(AuthenticationStatus.authenticated);
} on AppwriteException {
} catch (e) {
_logger.log(Level.SEVERE, "$e");
} finally {}
}
Execution Log:
I/flutter (26475): INFO: 2023-04-15 11:05:43.742769: Register method called of Authentication Repo.
I/flutter (26475): INFO: 2023-04-15 11:05:43.743017: Instance of 'ClientIO'
I/flutter (26475): INFO: 2023-04-15 11:05:43.743228: Instance of 'Account'
It looks like you aren't logging if an AppwriteException occurs. Would you please try to use await and log that error
Sorry for the late reply. That was the reason. While I could not reproduce the exact situation again, I intentionally made an exceptional situation by making the password length to less than 8 characters and running the above snippet. Since I am not logging anything in the on block it seemed that it got stuck while it was actually throwing an error. I thought that the catch block would still execute if the on block condition matches for which I wrote the code like that but it is not the case. So I found out that the exact behaviour I was looking for was on AppwriteException catch (e) {} (As this would match the exception type as well as give me a copy of the exception object).
Thanks again!
[SOLVED] Unable to create new user in dart async function
Recommended threads
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Flutter Android oAuth is no more working
I currently don't get the oAuth login to work in flutter android. it works on ios and on web. but when try to use it on Android, i get to the point where the ca...
- I'm experiencing a critical bug on Appwr...
Hey <@870607367597850624> team / support š I'm experiencing a critical bug on Appwrite Cloud that's blocking my production Flutter app. I've already filed GitH...