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
- Custom emails
What happen if I use a third party email provider to customize my emails and my plan run out of emails/month? Appwrite emails are used as fallback sending emai...
- Realtime with multiple connections
I need the Realtime on multiple Collections for diffrent applicational logic. So my question is: Is there a way to have only 1 Websocket connection or do I need...
- Can't login or deploy functions in Appwr...
Hello, since i updatet to the appwrite cli 6.1.0 i can't login or deploy functions with the cli. When i call the command: "appwrite get account --verbose" i ge...