Back

Fixing a general_unauthorized_scope user error

  • 0
  • Users
  • Flutter
  • Web
  • Accounts
tahakhawaja
2 Sep, 2023, 08:29

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

TypeScript
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();
    }

}
TL;DR
The user encountered a general_unauthorized_scope error when using a chatbot. They temporarily disabled CORS restrictions to troubleshoot the issue. The user also mentioned adding a login function after encountering the error initially, which resolved the issue temporarily before it reappeared. Some discussion took place about the Appwrite SDK version and permissions, but no specific solution was mentioned. Solution: Since no specific solution was provided in the thread, it is unclear how to fix the general_unauthorized_scope error. It would be helpful to check the Appwrite documentation or reach out to their support for assistance in resolving the issue.
D5
2 Sep, 2023, 11:57

What version of Appwrite

D5
2 Sep, 2023, 11:57

It seems like you have not set permissions

tahakhawaja
2 Sep, 2023, 20:51

No I have crossed it out for this post, I believe it is v1

D5
2 Sep, 2023, 20:53

But v1.x? 1.4,1.3...?

tahakhawaja
2 Sep, 2023, 20:53

I will have to double check and let you know. Is there a specific version I should be using?

D5
2 Sep, 2023, 20:54

Nope, but the solution will probably depend on the version you're using

tahakhawaja
3 Sep, 2023, 07:44

it's version 1.3.8 @D5

safwan
3 Sep, 2023, 07:48

What are the permission on the collection?

tahakhawaja
3 Sep, 2023, 22:15

I've selected create, read, update, delete. Those are the current permissions.

tahakhawaja
4 Sep, 2023, 06:12

?

safwan
4 Sep, 2023, 06:21

For "any" or "users" or something else?

tahakhawaja
4 Sep, 2023, 06:21

Any

safwan
4 Sep, 2023, 06:22

And just to be sure, you're getting the error in which line exactly?

safwan
4 Sep, 2023, 06:24

Also, which version of the appwrite sdk are you using?

alza
4 Sep, 2023, 17:29

@safwan

safwan
4 Sep, 2023, 17:58

That’s the version of the Appwrite server. I mean the version of the SDK

alza
4 Sep, 2023, 18:01

Oh sorry

tahakhawaja
4 Sep, 2023, 19:23

This is what i have in my pubspec.yaml file:

dependencies: flutter: sdk: flutter appwrite: ^9.0.1

tahakhawaja
4 Sep, 2023, 23:19

This problem has been solved

safwan
5 Sep, 2023, 04:39

Can I ask how you solved it?

tahakhawaja
5 Sep, 2023, 04:41

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.

safwan
5 Sep, 2023, 04:45

CORS issue? Have you added the application as a platform in your Appwrite project?

tahakhawaja
5 Sep, 2023, 04:46

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.

ideclon
5 Sep, 2023, 08:22

You can mark a post as solved by adding [SOLVED] to the beginning of the title

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more