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();
}
}
What version of Appwrite
It seems like you have not set permissions
No I have crossed it out for this post, I believe it is v1
But v1.x? 1.4,1.3...?
I will have to double check and let you know. Is there a specific version I should be using?
Nope, but the solution will probably depend on the version you're using
it's version 1.3.8 @D5
What are the permission on the collection?
I've selected create, read, update, delete. Those are the current permissions.
?
For "any" or "users" or something else?
Any
And just to be sure, you're getting the error in which line exactly?
Also, which version of the appwrite sdk are you using?
@safwan
Thatβs the version of the Appwrite server. I mean the version of the SDK
Oh sorry
This is what i have in my pubspec.yaml file:
dependencies: flutter: sdk: flutter appwrite: ^9.0.1
This problem has been solved
Can I ask how you solved it?
There were CORS restrictions preventing me from sending requests to our chatbot. Temporarily shut them off using a different browser than chrome. Originally I had installed an extension on Chrome to disable CORS but it seems like the extension wasnβt working properly until I tried it on a different browser.
CORS issue? Have you added the application as a platform in your Appwrite project?
Yes I think the CORS issue is appearing as an issue for our external chatbot. We need to configure it to allow requests from our website.
You can mark a post as solved by adding [SOLVED] to the beginning of the title
Recommended threads
- Current User is Not authorized
recreating same Thread
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...