Ryan BaigOriginal post
Rank 2: Process
here's the code for my API:
JavaScript
// /api/getbots.js
const sdk = require('node-appwrite');
async function getBotLinks(JWT) { console.log(JWT) console.log('1')
try { const client = new sdk.Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('pysec-tools') // project .setJWT(JWT) const account = new sdk.Account(client);
const databases = new sdk.Databases(client); const result = await databases.listDocuments( 'db', // databaseId '66f3feb30027fc479578', // collectionId [] // queries (optional) ); console.log(result) return [result, null]; } catch (error) { return [false, error]; // Return false and the error }}
export default async function handler(req, res) { const { JWT } = req.body; // Initialize variables let result = null; let msg = '';
try { // Correctly destructuring the array returned from checkSession [result, msg] = await getBotLinks(JWT.jwt); } catch (err) { console.log('ERROR!') console.log(err.stack) return res.json({ result: null, message: err.stack }); }console.log(result)console.log(msg) // Return the response with logged_in and message return res.json({ result: result, message: msg });}the logs:
ill share in next msg
Summary
Developers are having JWT permission issues when trying to list documents in an API. The error message states that the user is not authorized. The issue lies in the server-side code, not the client-side. They should ensure that the proper permissions are set up for the user in the Appwrite console.