[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
- [ENHANCEMENT] Use the custom Next.js dep...
Deployment adapters on Next.js are now stable! This means that we don't have to stick to the limitations of sniffing out build outputs and manually moving or mo...
- NextJS builds sudden runtime_timeout
My builds suddenly stopped working. Activating old prebuilt snapshots work, but redeploying that same code produces builds that throw runtime_timeout FRA region
- Project paused?
Hello, I have two Appwrite projects and I can not resume them for some reason. I'm using the free plan, and I saw in the pricing page that 2 free projects are a...