Back

[SOLVED] The current user is not authorized to perform the requested action

  • 0
  • Users
  • Databases
  • Apple
dch09
12 Sep, 2023, 20:25

After signing up with email I'm trying to create new document - Profile to be more precise. It contains the username and user id. I don't really understand why there's any issue at all — Collection profiles has create permission set to all users.

TL;DR
Title: [SOLVED] The current user is not authorized to perform the requested action; Solution: The issue was caused by setting `Role.guests` in the permissions. Removing this line solved the problem. It is important to note that users can only set permissions for all users or any, but not guests.
Drake
13 Sep, 2023, 05:21

What exactly are the permissions? Maybe share a screenshot

dch09
13 Sep, 2023, 10:13
dch09
13 Sep, 2023, 10:16

My goal is to create profile document with user.id when user managed to successfully register an account.

Preferably I'd like to allow this user to edit created profile later, and all guest & authenticated users should be able to read it.

dch09
13 Sep, 2023, 10:16

At the moment, it fails to create the document.

dch09
13 Sep, 2023, 10:16

Therefore additional permissions are a future goal.

ideclon
13 Sep, 2023, 11:54

Not sure why creation is failing, but for other permissions, when creating the Document, you can set custom permissions on it, as long as you turn on Document security

dch09
13 Sep, 2023, 16:01

I've managed to "solve" this by calling account.createEmailSession after creating an account. Is it the expected behaviour, that creating an account doesn't automatically return new session?

Guille
13 Sep, 2023, 16:09

Yes, it's the expected behavior, the flow at this moment, requires to call createEmailSession to have one. Maybe you can create a new issue to discuss this behavior with the community

dch09
13 Sep, 2023, 16:09

Glad to hear that. Thanks for clarifying!

dch09
13 Sep, 2023, 16:11

[SOLVED] The current user is not authorized to perform the requested action

dch09
13 Sep, 2023, 16:25

The current user is not authorized to perform the requested action

dch09
13 Sep, 2023, 16:26

I thought that the issue is solved but unfortunately no.

When creating Profile Document, this is the error I get: Permissions must be one of: (any, users, user:1CD7E806-E117-4ED4-B15E-7BEFC1316D80, user:1CD7E806-E117-4ED4-B15E-7BEFC1316D80/unverified, users/unverified)

dch09
13 Sep, 2023, 16:26
dch09
13 Sep, 2023, 16:27

and here's the code for creating document:

TypeScript
func createProfile(for userID: String, username: String) async throws {
        _ = try await create(
            Profile.self,
            collectionID: CollectionType.profiles.rawValue,
            documentID: UUID().uuidString,
            data: [
                "userID": userID,
                "username": username
            ],
            permissions: [
                Permission.update(Role.user(userID)),
                Permission.read(Role.users()),
                Permission.read(Role.guests())
            ]
        )
    }
dch09
13 Sep, 2023, 16:28

My understanding of Permissions & Document Security is that I can set global rules via Permissions in Collection settings — in this case it's the all users can create Profile documents

dch09
13 Sep, 2023, 16:30
TypeScript
permissions: [
                Permission.update(Role.user(userID)),
                Permission.read(Role.users()),
                Permission.read(Role.guests())
            ]

should declare Permissions (Document Security) rules for this single document, right?

dch09
13 Sep, 2023, 16:32

Do I need to specify in the Collection Permissions that every document should be accessible to read for guests and all users?

dch09
13 Sep, 2023, 16:33

If I pass null value to permissions in create function, it automatically creates the Permission for read / delete / update and create with correct user id

dch09
13 Sep, 2023, 17:46

Ok, it looks like setting Role.guests was the issue. Removing this line solved the issue. I find it odd that according to some answers in the support channel, user can only set permissions for all users or any, but not guests.

Drake
13 Sep, 2023, 19:30

[SOLVED] The current user is not authorized to perform the requested action

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