
frontend:React backend: nodejs
Main Issue: I have the user logged in in React and call a server function. On the serverside nodejs function I call await account.get() but it isn't detecting the logged in user.
I call the function in react using: await functions.createExecution(functionId) Permissions: I have allowed users to use the function in the Execute Access settings of the function and selected "Users"
Result of the server function after calling it :" User (role: guests) missing scope (account)
I am new to Appwrite so maybe I am missing something. Thanks in advance

Did you do anything else before account.get()
? How are you setting the user?

@Steven I use import { Account, Client } from 'node-appwrite'; and initialize the client and account like this: const client = new Client(); client .setEndpoint(process.env.APPWRITE_ENDPOINT) .setProject(process.env.APPWRITE_FUNCTION_PROJECT_ID) .setKey(process.env.APPWRITE_API_KEY);
const account = new Account(client); and then I do: try { // Get user details to check authentication const user = await account.get();
// If user details are received, the user is authenticated
return res.json(JSON.stringify({ authenticated: true, user }));
} catch (err) { // If there's an error or user details are not received, the user is not authenticated return res.json(JSON.stringify({ authenticated: false, error: err.message })); }

The env variable APPWRITE_ENDPOINT is my private ip address 192.168.1.x. I also set my APPWRITE_API_KEY and PROJECT_ID in the console. My react app APPWRITE_ENDPOINT is also set to the same private ip address. I tried using http://localhost/v1 in my server function but I kept getting a connection error, and had to change it to my private ip for it to work anyway I am still getting the same error: "User (role: guests) missing scope (account)"

I am now getting (role: applications) missing scope (account)

You can't use account.get() with an API key

So when a user executes a function, a JWT token is created and passed to the function in the headers. You'll need to get that and call setJWT() instead of setKey()


Thank you @Steven I will try that.

@Steven how would I retrieve the user ID after setting the JWT token?

If you only need the user id, there's a header with that already.

yeah, but if I want to get the user ID from the JWT token to make sure it is the right user

btw, thanks for your help 🙂

It will be the right user.
But how does a user get their user id in general (let's say client side)?

I dont know 🙂 I am just starting, but I will have to make some queries that belong on the user relation
Recommended threads
- Use cloudflare origin certificate instea...
Hello! Is it possible to use cloudflare origin certificates instead of let's encrypt? We manage all ssl certs in our cloudflare account and our VMs has a firewa...
- Error getting session: AppwriteException...
I get this error `Error getting session: AppwriteException: User (role: guests) missing scope (account)` when running in prod. As soon as I try running my app o...
- Failed to verify JWT. Invalid token: Exp...
Hi I am trying to call a function from my mobile app, but I am receiving "Invalid token expired." My code looks more or less like this ```ts // from my app ...
