Back

fetching teams error

  • 0
  • Web
  • Cloud
Old fella
14 Jan, 2025, 11:19

when I do this :

TypeScript
import { account } from '$lib/appwrite';
let loggedInUser: any;
async function init() {
    try {
        console.log('Starting App');
        loggedInUser = await account.get(); // Check if the user is already logged in
        console.log(loggedInUser.name);
    } catch (error) {
        loggedInUser = null;
        console.error('Error fetching logged-in user:', error);
    }
}
init();```
I got this  ressult :
```code: 401,
  type: 'general_unauthorized_scope',
  response: {
    message: 'User (role: guests) missing scope (account)',
    code: 401,
    type: 'general_unauthorized_scope',
    version: '1.6.1'
  }
}```
TL;DR
Developers are encountering a 401 error (general_unauthorized_scope) when trying to fetch teams. The issue seems to be with importing the user from local storage to check authority. The code snippets provided attempt to rectify the problem, but the unauthorized scope error persists. This might be due to missing user scopes (such as 'account'). Further troubleshooting is necessary.
Old fella
14 Jan, 2025, 11:19

when I do this :

TypeScript
import { Account, AppwriteException, Client, Teams } from 'appwrite';
import { json } from '@sveltejs/kit';
import dotenv from 'dotenv';
import { account } from '$lib/appwrite';
dotenv.config();
const endpoint = import.meta.env.VITE_APPWRITE_ENDPOINT;
const projectId = import.meta.env.VITE_APPWRITE_PROJECT_ID;
if (!endpoint || !projectId) {
    throw new Error('Missing Appwrite configuration in environment variables');
}
const client = new Client();
client
    .setEndpoint(endpoint)
    .setProject(projectId); // Replace with your project ID
 let loggedInUser;
async function init() {
    try {
        console.log('Starting App');
        loggedInUser = await account.get(); // Check if the user is already logged in
        console.log(loggedInUser.name)
    } catch (error) {
        loggedInUser = null;
    }
}
init();

```Starting App
signed in as :[object Promise]
true
file:///C:/Users/hi/Desktop/test/appwrite%20-%20Copy/node_modules/appwrite/dist/esm/sdk.js:428
                    throw new AppwriteException(data === null || data === void 0 ? void 0 : data.message, response.status, data === null || data === void 0 ? void 0 : data.type, data);
                          ^

  code: 401,
  type: 'general_unauthorized_scope',
  response: {
    message: 'User (role: guests) missing scope (account)',
    code: 401,
    type: 'general_unauthorized_scope',
    version: '1.6.1'
  }
}```
Old fella
14 Jan, 2025, 11:22

I think the porblem is that the user isn't directly imported from localstorage to check authority

neutrino2211
14 Jan, 2025, 11:42

What are you trying to do specifically?

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