Back

How to debug user right issue ?

  • 0
  • Databases
tnn
8 Mar, 2024, 16:01

hi ! I'm using npm appwrite integration, i'm trying to save a mesage in my brand new collection, but i have this error :

TypeScript
    at Client.<anonymous> (./node_modules/appwrite/dist/cjs/sdk.js:393:27)
    at Generator.next (<anonymous>)
    at fulfilled (./node_modules/appwrite/dist/cjs/sdk.js:24:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 401,
  type: 'user_unauthorized',
  response: {
    message: 'The current user is not authorized to perform the requested action.',
    code: 401,
    type: 'user_unauthorized',
    version: '0.12.111'
  }
}```

here's my code so far :
TypeScript
    try {
        // Save the message to Appwrite database
        const response = await databases.createDocument(
            APPWRITE_DATABASE_ID,
            APPWRITE_COLLECTION_ID,
            'unique()',
            {
                message: message,
            }
        );

        await interaction.reply({ content: `Message saved with ID: ${response.$id}`, ephemeral: true });
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: 'There was an error while saving the message.', ephemeral: true });
    }
TypeScript
I've double checked Database id (with letters), the collection id (with numbers), and my api rights accept all database related actions. 
Can i make the error message more specific on the missing right ? 

thank you !
TL;DR
Developers are attempting to save a message to an Appwrite database but encounter a user authorization issue. The error message indicates the current user lacks authorization for the action. To address this, ensure proper permissions are set and that the API rights include all necessary database actions. To make the error message more specific, consider refining the permissions or checking the user's access rights.
D5
8 Mar, 2024, 16:08

Do you have set permissions?

tnn
8 Mar, 2024, 16:10

i'm discovering appwrite, so maybe ? πŸ˜…

tnn
8 Mar, 2024, 16:11

you are talking about that ?

D5
8 Mar, 2024, 16:13

Is your code running server side or client side

tnn
8 Mar, 2024, 16:14

it's a discord bot, so i will say server side, the error is generated by discord

ideclon
8 Mar, 2024, 16:17

How are you creating the Client?

tnn
8 Mar, 2024, 16:20

for dev purpose, i have a node server in my pc, i launch the bot with node src/index.js

D5
8 Mar, 2024, 16:26

@tnnIs this appwrite cloud or you're self-hosting?

tnn
8 Mar, 2024, 16:30

appwrite cloud πŸ™‚

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