Back

Suddenly getting: Appwrite Exception: general unauthorized scope

  • 0
  • Self Hosted
  • Flutter
Ponguta_
2 Oct, 2023, 23:19

Hello, has been a long time, I have a question:

Recently I have started getting this error on Appwrite 1.2.1: Appwrite Exception: general unauthorized scope I dont know what have changed, but it was working normally and suddenly it doesn't anymore.

I'm using flutter web, and even when I try to connect from the developer browser it works, but when I deploy the code to the server, the error shows up.

This is a portion of the code:

TypeScript
    try {
      await ApiService.instance?.login(
        email: usernameController.text,
        password: passwordController.text,
      );
      var resTeam = await ApiService.instance?.getListaEquipos();
      Navigator.pushReplacement(
        context,
        MaterialPageRoute(builder: (context) => const MyApp()),
      );
    } on AppwriteException catch (e) {
      print(e);
    }
TypeScript
class ApiService {
  static ApiService? _instance;

  late Client client;
  late Account account;
  late Teams teams;
  late Databases db;
  late Storage storage;
  late Functions functions;

  ApiService._internal() {
    Client client = Client(endPoint: AppConstant.endPoint)
        .setProject(AppConstant.projectid)
        .setSelfSigned(status: true);
    account = Account(client);
    teams = Teams(client);
    db = Databases(client);
    storage = Storage(client);
    functions = Functions(client);
  }

  static ApiService? get instance {
    _instance ??= ApiService._internal();
    return _instance;
  }

Future<models.Session> login(
      {required String email, required String password}) async {
    try {
      var session =
          await account.createEmailSession(email: email, password: password);
      print(session.toMap());
      return session;
    } catch (e) {
      rethrow;
    }
  }

  Future getListaEquipos() async {
    var res = await teams.list();
    return res;
  }

Any idea on whats going on? Any help is really appreciatted.

TL;DR
User is receiving the error "Appwrite Exception: general unauthorized scope" when trying to connect to the Appwrite server from their Apache server. It was working fine before and still works on their local machine and developer browser. They are using Flutter web. They provide a portion of their code that involves a login and accessing a list of teams. They're asking for help and any ideas on what could be wrong. Potential solution: The user could check if there are any leftover bad sessions. They could also try checking how many sessions the user has.
Drake
2 Oct, 2023, 23:21

Check how many sessions the user has

Ponguta_
2 Oct, 2023, 23:26

Hello Steven, thanks for your answer. I have actually cleaned them up, because at some point I was getting other type of error, after several tries.

Im printing Session on login method, and I'm getting this:

TypeScript
{$id: 651b50c46d2b0b001d3b, $createdAt: 2023-10-02T23:22:44.938+00:00, userId: 64373b5a882bdee843de, expire: 2024-10-01 23:22:44.447, provider: email, providerUid: test@gmail.com, providerAccessToken: , providerAccessTokenExpiry: , providerRefreshToken: , ip: 172.16.100.1, osCode: WIN, osName: Windows, osVersion: 10, clientType: browser, clientCode: OP, clientName: Opera, clientVersion: 102.0, clientEngine: Blink, clientEngineVersion: 116.0.0.0, deviceName: desktop, deviceBrand: , deviceModel: , countryCode: --, countryName: Unknown, current: true}

The weird thing about this, is it was working just fine, as I said, it does work from my local machine to the appwrite server, but from my apache server to appwrite server it suddenly does not.

Drake
2 Oct, 2023, 23:26

Maybe there's also some leftover bad season

Ponguta_
2 Oct, 2023, 23:28

What do you mean? Sorry

Ponguta_
2 Oct, 2023, 23:30

Seems like is not saving any cookie

Drake
3 Oct, 2023, 01:57

Is that domain your appwrite endpoint?

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