[SOLVED] Trying to store user preferences when creating an account
- 1
- 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
- Update User Error
```ts const { users, databases } = await createAdminClient(); const session = await getLoggedInUser(); const user = await users.get(session.$id); if (!use...
- apple exchange code to token
hello guys, im new here π I have created a project and enabled apple oauth, filled all data (client id, key id, p8 file itself etc). I generate oauth code form...
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...