Hey everyone, i'm running into an issue when storing user data in a database collection. Currently, the function does not run or store any data in the collection. The way it works right now is a user first created an account, so I run the "createUser" function, and then in a subsequent webpage they select up to a total of 21 topics, which are added in a database collection associated with their user id. The function I run for this is "createUserTopics". Is there something wrong with the way I am handling my code?
// Registering the User (Sign Up)
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("Working so far");
print("Created user ID: ${user.$id}");
// storing the user role in the database after successful registration
await databases.createDocument(
databaseId: 'xxx',
collectionId: 'xxx',
documentId: user.$id,
data: {
'userid': user.$id,
'role': role
});
// Automatically login user after account creation
try {
Map<String, dynamic> loginResult = await loginUser(email, password);
bool loginSuccess = loginResult['success'];
if (loginSuccess) {
print("User automatically logged in after registration");
} else {
print("Failed to automatically log in");
}
} catch (e) {
// Handle any exceptions thrown by loginUser
if (e is AppwriteException) {
print('Failed to automatically log in: ${e.message}');
} else {
print('An unknown error occurred while trying to log in: $e');
}
}
return user.$id;
} on AppwriteException catch(e) {
return e.message.toString();
}
}
// Function to update user preferences with selected topics
Future<String> createUserTopics(String userId, List<String> topics) async {
try {
// Update the document with the list of topics
await databases.createDocument(
databaseId: 'xxx',
collectionId: 'xxx',
documentId: userId,
data: {
'topics': topics
},
);
print("User preferences updated successfully");
return "User preferences updated successfully";
} catch (e) {
print("Error updating user preferences: $e");
return "Error updating user preferences";
}
}
What's the error you're getting, and where?
You should also check whether the right permissions are granted
I'm not getting any error at all, which is why i'm a bit confused
Does the user get created?
Recommended threads
- Paused project can't activate
I have failed to reactivate one my projects which had been paused
- Site deployment keeps getting failed
Hi good folks, need a hand with Sites deploy Error on every deploy: Synchronous function execution timed out... duration doesn't exceed 30 seconds [exact log ...
- Relation Question
How do I create a relation from table y to an others x.$id. in my example I have a users table where I use Appwrites unique User IDs and I want other tables fo...