Back

How do I retrieve jwt on the server?

  • 0
  • Self Hosted
  • Accounts
  • Web
  • Users
kstulgys
9 Jun, 2023, 08:12

So I create jwt on the frontend for the user: const promise = account.createJWT();

How do I retrieve it on the backend?

TypeScript
client
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    .setProject('[PROJECT_ID]')                // Your project ID
    .setJWT('eyJJ9.eyJ...886ca');               // Your secret JSON Web Token
TL;DR
The user wants to know how to retrieve a JWT on the server. The JWT can be obtained from the `APPWRITE_FUNCTION_JWT` variable. To retrieve the JWT on the backend, use the `setJWT` function and pass the JWT as a parameter.
animeyeet
9 Jun, 2023, 08:20

from client send it to server

kstulgys
9 Jun, 2023, 08:51

is JWT attached to every req?

animeyeet
9 Jun, 2023, 09:41

No

Binyamin
9 Jun, 2023, 12:41

If a user is execution the function then any time is doing so a fresh JWT will be sent to you inside the APPWRITE_FUNCTION_JWT variable.

Like so

TypeScript
  .setJWT(req.variables.APPWRITE_FUNCTION_JWT ?? '')

Check here for more details: https://appwrite.io/docs/functions#functionVariables

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