[SOLVED] Trying to store user preferences when creating an account
- 1
- Resolved
- Flutter
- Web
- Databases
- Accounts
- Users
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();
}
}
What is the collection structure?
Attributes
its the user id, and a role which can take the value "entrepreneur" or "coach"
Try to log this before sending
data: {
'userId': user.$id,
'role': role
})
To see that none of these two values are empty, as if it will be send empty and one of them is required then it will be considered as Missing required attribute
So I currently get this error:
"invalid document structure: Missing required attribute: userId"
Am i doing something wrong for the user id?
Can you share screenshot of the attribute screen?
This is how it looks
userid or userId?
userid
Seems like in the create document part/function you're trying to save an attribute that doesn't exists called userId, because your attribute seen in the screenshot is "userid" with the I not in caps letters
How would you suggest I fix this in order to store the attribute? Is there any part of the code I should correct?
Just put the i not in capital letters or change the attribute name by deleting it and adding it again (note, previous data will be lost)
Are you referring to this, and saying make the capital I an i instead?
'userId': user.$id,
This is how will look your code after being modified:
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
//Here the I should not be in caps, fixed in the code below
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();
}
}
Yes
thank you! i'll give this a try. appreciate your help!
Confirm me if it works to mark this as solved π
It works! Thanks again!!
<a:agooglethumbsup:635256484682530825>
[SOLVED] Trying to store user preferences when creating an account
Recommended threads
- Urgent help with removed databases
Hi <@564158268319203348> <@501784879638249472> I wrote to paid plan support about this but no response as of yet⦠About an hour ago one of the interns from o...
- MariaDB refuses to connect to appwrite
Earlier, I tried updating my Appwrite version from 18.1.x to the latest release because my Flutter package required it to function properly. I used the official...
- Custom API domain is unreachable
Earlier my custom api domain was working fine. Now it seems to be offline without a trace a few hours later. I didn't change anything, all the relevant DNS reco...