Back

The current user is not authorized to perform the requested action (401)

  • 0
  • Android
  • Flutter
  • Databases
  • Auth
Mingu
15 Dec, 2024, 13:44

I want to create a document associated with user after log in with OAuth. The user were logged in, but Appwrite said user is unauthorized. User is logged in with Google Oauth. When I want to get the document user is associated with after that, appwrite returned this.

TypeScript
I/flutter (26735): session created
I/flutter (26735): 2
I/flutter (26735): Check user document
I/flutter (26735): Get user document
I/flutter (26735): <my name> 675b1cd649fddd34b9b8 2024-12-12T17:26:46.304+00:00
I/flutter (26735): get document by id
I/flutter (26735): AppwriteException: user_unauthorized, The current user is not authorized to perform the requested action. (401)

When I hover over the user id in document's permission, it return the correct user. Here are the functions

TypeScript
    print("Get user document");
    print("${_currentUser.name} ${_currentUser.$id} ${_currentUser.$createdAt}"); // Here it print the current user info, which are correct
    String id = _currentUser.$id;
    return await DatabaseAPI().getUserDocumentById(id);
  }```
``` Future<Document> getUserDocumentById(String id) async {
    print("get document by id");
    try {
      await account.get();
      return await databases.getDocument(
        databaseId: DATABASE_ID,
        collectionId: USERS_COLLECTION_ID,
        documentId: id,
      ); // <-- this said user is unauthorized
    } catch (e) {
      print(e.toString());
      return await createBlankDocument(id);
    }
  }```
TL;DR
Developers are encountering a 401 unauthorized error with Appwrite when trying to access a user document even though the user is logged in with Google OAuth. Possible causes might be related to permissions set within the document. Double-check the authorization settings, as well as any potential issues with session creation.
Mingu
15 Dec, 2024, 13:46

Since I keep logging in and out because of this, I'm not sure will this affect my account.

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