Back

[SOLVED] Cannot read the Database

  • 0
  • Databases
  • Web
  • Cloud
RangerDev
17 May, 2023, 19:34

Basically what the title states, cant read the database. It returns the following error

TypeScript
AppwriteException: The current user is not authorized to perform the requested action.
    at Client.<anonymous> (file:///C:/Users/meera/GithubDesktop/PitchFork/node_modules/appwrite/dist/esm/sdk.js:391:27)
    at Generator.next (<anonymous>)
    at fulfilled (file:///C:/Users/meera/GithubDesktop/PitchFork/node_modules/appwrite/dist/esm/sdk.js:22:58)
    at processTicksAndRejections (node:internal/process/task_queues:96: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.10.19'
  }
}

I am really new to appwrite so help is appreciated.

Here is the code:

TypeScript
import { Client, Account, ID, Databases, Permission, Role, Teams } from 'appwrite';

const client = new Client();
const account = new Account(client);

client
    .setEndpoint('https://cloud.appwrite.io/v1')
    .setProject('646521b8048d4efcd171');


const databases = new Databases(client);


const promise = databases.listDocuments('646522094815b3cf7be4', '64652215e10e469f9e37');


promise.then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});


// create the user session
account.createEmailSession('me@example.com','password').then(function (response) {
    console.log(response); // Success
}, function (error) {
    console.log(error); // Failure
});
TL;DR
Title: [SOLVED] Cannot read the Database Messages: - The user cannot read the database and is receiving a 401 error code. - Solution: The user does not have the necessary permissions. - Add permissions for the user or user group in the Appwrite console by going to the "Settings" tab inside the collection. - Make sure the user has access to Read the collection and add the necessary permissions. - The provided code is creating a new user session, but does not address the authorization issue.
Binyamin
17 May, 2023, 19:34

Everything seems fine.

RangerDev
17 May, 2023, 19:34

Cannot read the Database

RangerDev
17 May, 2023, 19:35

why is it giving me the error?

Binyamin
17 May, 2023, 19:35

In your Appwrite console add permission to the collection

RangerDev
17 May, 2023, 19:35

??

RangerDev
17 May, 2023, 19:35

ok

RangerDev
17 May, 2023, 19:36

you mean a create a collection called Permission?

Binyamin
17 May, 2023, 19:36
Binyamin
17 May, 2023, 19:36

You'll need to go to Settings tab inside your collection

Binyamin
17 May, 2023, 19:36

Then you can add and set permission for user(s) group

Binyamin
17 May, 2023, 19:37

In my example you can see Any have access to Read this collection

RangerDev
17 May, 2023, 19:37

yep

RangerDev
17 May, 2023, 19:37

got it

RangerDev
17 May, 2023, 19:37

it works

RangerDev
17 May, 2023, 19:37

tysm @Binyamin

Drake
17 May, 2023, 19:59

[SOLVED] Cannot read the Database

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