Skip to content
Back

user_unauthorized after login

  • 0
  • Databases
  • Flutter
  • Auth
  • Cloud
Note
1 Dec, 2024, 18:32

when i logout and try to login again, the session is created but when i get navigated to the dashboard i start getting errors that the user isnt authorized to perform the request

all of my collections have roles set to users only unless those that need else

now that i got the error, if i hot restard the app it works perfectly

so the issue only happens for some reason when i logout and try to login again.

TypeScript
Future<Session> login(String email, String password) async {
    try {
      final session = await appwriteService.account.createEmailPasswordSession(
        email: email,
        password: password,
      );

      // Store session state
      final prefs = GetStorage();
      await prefs.write('sessionExists', true);

      // Initialize client with new session
      await initializeAppwrite();

      // ...rest of your login logic...
      print('session id: ${session.$id}');
      return session;
    } catch (e) {
      print('error in making session: $e');
      rethrow;
    }
  }

  Future<void> logout() async {
    try {
      await appwriteService.account.deleteSession(sessionId: 'current');
      final prefs = GetStorage();
      await prefs.write('sessionExists', false);
      isAuthenticated.value = false;
      user.value = null;
    } catch (e) {
      rethrow;
    }
  }

I/flutter ( 5078): AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401)

i considered a way go around it, by using some library to restart the app when u logout, i tried pheonix but it didnt work

TL;DR
Issues with unauthorized user error after logout and login again. Error occurs upon navigating to the dashboard, indicating user lacks authorization. Temporary solution is to hot restart the app. Consider updating code for handling sessions upon login and logout to resolve the problem.
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