Rank 2: Process
I get an error message when creating an account and attempting to store the role and user id in a database collection. What am i doing wrong in my code? These are the errors I get in the front-end console:
errors:
main.dart.js:45231 POST http://178.128.196.153/v1/databases/64e70d5fb77f8c332745/collections/64e70d954009050a62ec/documents 400 (Bad Request)
"invalid document structure: Missing required attribute: userId"
code:
Future<String> createUser(String name, String email, String password, String role) async {
try {
final user = await account.create(
userId: ID.unique(),
email: email,
password: password,
name: name);
print("New User created");
print("Created user ID: ${user.$id}");
// storing the user role in the database after successful registration
await databases.createDocument(
databaseId: '64e70d5fb77f8c332745',
collectionId: '64e70d954009050a62ec',
documentId: user.$id,
data: {
'userId': user.$id,
'role': role
});
return "success";
} on AppwriteException catch(e) {
return e.message.toString();
}
}
