Rank 2: Process
I get this error, when users send a request to our chatbot. The current user flow is the user, creates an account, and then can head over to the chatbot and interact with it. I added an additional function that logs in the user after they create an account. I initially did not have the function responsible for logging in a user after they create an account and got these errors. After adding the login function this error had disappeared, and the chatbot was working. It suddenly stopped working again and i'm not sure why.
main.dart.js:45239 GET http://xxxxxxxx/v1/account? 401 (Unauthorized)
main.dart.js:27943 Failed to get user ID: AppwriteException: general_unauthorized_scope, User (role: guests) missing scope (account) (401)
main.dart.js:4805
Future loginUser(String email, String password) async {
try {
final user = await account.createEmailSession(email: email, password: password);
print("User logged in");
return true;
} catch (e) {
return false;
print(e);
}
}
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}");
await databases.createDocument(
databaseId: 'xxx',
collectionId: 'xxx',
documentId: user.$id,
data: {
'userid': user.$id,
'role': role
});
var loginSuccessOrError = await loginUser(email, password);
if (loginSuccessOrError == true) {
print("User automatically logged in after registration");
} else if (loginSuccessOrError is AppwriteException) {
print('Failed to automatically log in: ${loginSuccessOrError.message}');
} else {
print('An unknown error');
}
return "success";
} on AppwriteException catch(e) {
return e.message.toString();
}
}