1

I'm unable to make a request to my backend using a JWT created when the user logs in in the frontend.

Everytime I try, even if the access to the collection is set to role:all, I get this error from the backend:

{
    "statusCode": 500,
    "code": "401",
    "error": "Internal Server Error",
    "message": "<User> (role: member) missing scope (collections.read)"
}

I'm using Appwrite Node SDK for server part and Appwrite web sdk in the frontend.

This is my login script where I generate the JWT token:

import { Appwrite } from "appwrite";

export const login = async (email, password) => {
    const api = new Appwrite();
    api.setEndpoint(import.meta.env.VITE_APPWRITE_URL);
    api.setProject(import.meta.env.VITE_APPWRITE_PROJECT);
    await api.account.createSession(email, password);
    const user = await api.account.get();
    const jwt = await api.account.createJWT();
    return {
        jwt: jwt.jwt,
        user: {
            id: user.$id,
            email: user.email,
            name: user.name
        },
    }
}

What am I missing?

Note: I am running everything inside Docker containers.

1 Answers1

0

(role: member) missing scope (collections.read)

This error indicates you're trying to fetch a collection rather than documents in your collection. Make sure you're using databases.listDocuments().

const sdk = require('node-appwrite');

// Init SDK
const client = new sdk.Client();

const databases = new sdk.Databases(client, '[DATABASE_ID]');

client
    .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setJWT('919c2d18fb5d4...a2ae413da83346ad2') // Your JWT token
;

const promise = databases.listDocuments('[COLLECTION_ID]');

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

Note: this sample code uses node-appwrite version 7.0.2 and is meant for Appwrite version 0.15.X.

Steven Nguyen
  • 452
  • 4
  • 4