Back

issue creating record

  • 0
  • Self Hosted
  • Databases
Brinamite
28 May, 2024, 17:37

I have this barebones POST endpoint on Next JS.:

TypeScript
export async function POST(req:Request){
    try {
        const conversation = await req.json() as INewConversation;
        const {database,config} = await createSessionClient();
        const conv = await database.createDocument(config.databaseId,
            config.conversationCollectionId, 
            ID.unique(),
            conversation
        );
        return NextResponse.json(conv as unknown as IConversation);    
    }catch (error) {
        return new NextResponse(`Internal Error - ${error}`, { status: 500 })    }
}

Now, the conversation table has the attributes in attached image. It has relationships to the user and messages tables.

Permissions I made sure to tick them all for "Any role" for the main table and the relationship tabled.

How come I am still getting the below error on document creation:

"AppwriteException: The current user is not authorized to perform the requested action."

This seems like a very stupid mistake from my end but I have other tables which are working fine and this one just won't work. I am able to create entries from the GUI as an admin.

Appwrite docker log:

TypeScript
2024-05-28T17:36:56.829015933Z [Error] Timestamp: 2024-05-28T17:36:56+00:00
2024-05-28T17:36:56.829061804Z [Error] Method: POST
2024-05-28T17:36:56.829069100Z [Error] URL: /v1/databases/:databaseId/collections/:collectionId/documents
2024-05-28T17:36:56.829073822Z [Error] Type: Appwrite\Extend\Exception
2024-05-28T17:36:56.829079045Z [Error] Message: The current user is not authorized to perform the requested action.
2024-05-28T17:36:56.829083896Z [Error] File: /usr/src/code/app/controllers/api/databases.php
2024-05-28T17:36:56.829088082Z [Error] Line: 2839
TL;DR
Developers are facing authorization issues when creating records despite having set permissions correctly. The error "AppwriteException: The current user is not authorized to perform the requested action" is occurring. The issue may be due to missing permissions or roles setup for the user. One possible solution to resolve this problem is to double-check the permissions and roles assigned to the user for both the main table and the associated relationship tables. Make sure that all necessary permissions are granted to the user roles.
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