Back

AppwriteException: user_unauthorized, The current user is not authorized to perform the request

  • 0
  • Databases
  • Flutter
rosario
7 Nov, 2023, 21:19

Hi guys,

I am trying to create a document with a logged in user in a flutter app. Unfortunately, I get the error:

AppwriteException: user_unauthorized, The current user is not authorized to perform the request (401)

The document security is actived.

I understand from other posts that you advice to use the dart SDK. If this is the workaround for the problem, I think this is not a good solution. I do not want to use one API key for all write requests of all users. Could you please help me?

TL;DR
The user is getting an AppwriteException error stating that the current user is not authorized to perform the request. They are trying to create a document with a logged-in user in a Flutter app. The document security is activated and they do not want to use one API key for all write requests. The suggested solution is to allow all users Create permissions and then set the permissions for specific users or documents in the console. They may need to set write permissions for the collection and ensure they are not setting collection-level permissions if they do not want users to have access to the whole collection.
rosario
7 Nov, 2023, 21:19

here is the error

Kenny
7 Nov, 2023, 21:32

You need to add permissions for creating to the collection, I think.

rosario
7 Nov, 2023, 21:44

I add them sending the userID of the user

D5
7 Nov, 2023, 23:00

You're doing this server sided, throught an appwrite function?

rosario
7 Nov, 2023, 23:16

What do you mean by server sided? It is an Flutter mobile app.

D5
7 Nov, 2023, 23:20

Are you setting permissions for a different user, that is not the one using the app at such moment?

rosario
7 Nov, 2023, 23:20

No, it is the same user

D5
7 Nov, 2023, 23:23

Okay, I double checked and seems that's because you don't have set write permission, in the collection level for that user

rosario
7 Nov, 2023, 23:25

how do I do that? I defined Permission.write, see last screenshot

rosario
7 Nov, 2023, 23:26

Why should I set collection level permission? I do not want that an user has access to a whole collection

rosario
7 Nov, 2023, 23:28

that is why I set only document permissions

D5
7 Nov, 2023, 23:29

In the console, when you select the collection, you will need to set write for such user or users

D5
7 Nov, 2023, 23:30

In the section you see in this screenshot

rosario
7 Nov, 2023, 23:31

So either I add all users or for every specific user that I want he has access to some document I need to define in the console?

rosario
7 Nov, 2023, 23:32

to define him in the console

ideclon
7 Nov, 2023, 23:45

You can allow all users Create permissions. Then on Document creation, you can set the permissions for that Document (as you’re doing now)

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