
I deployed appwrite function that returns user jwt:
module.exports = async function (req, res) {
const jwt = req.variables.APPWRITE_FUNCTION_JWT;
res.json({ jwt });
};
When triggered through admin api I can see jwt in the logs, but when triggered in my app (locally) serverside I see jwt as empty string:
let token = await functions.createExecution('getCurrentUserJwt');
// token object:
{
token: {
'$id': '6494abfd1dcc5d578e3b',
'$createdAt': '2023-06-22T20:15:57.122+00:00',
'$updatedAt': '2023-06-22T20:15:57.129+00:00',
'$permissions': [],
functionId: 'getCurrentUserJwt',
trigger: 'http',
status: 'completed',
statusCode: 200,
response: '{"jwt":""}',
stdout: '',
stderr: '',
duration: 0.0022101402282714844
}
}
Why is this? Appwrite is deployed to digital ocean.

To br able to generate JWT the execution can be run only from a client side. As only when a client is executing the function, only then Appwrite will generate the JWT token

Yes before calling appwrite function I generate jwt client side account.createJwt()

Then call api endpoint that triggers createExecution

Api endpoint?

Waht you mean?

I'm execution function serverside

Triggering nextjs api endpoint

Got it

So in this use case you won't get the JWT automatically

If you want to get you'll need to pass it to next.

Then pass it to the function as data Or Initialize the server side SDK using the JWT

My initial idea is to maintain users jwt serverside without passing it from cookie

Does this make sense?

Yes, Have you check almost ssr of next by Matej?

?


Oh, will take a look

So getting back on my initial subject. The function will return jwt only if it's called client side, right?

Yes

What I mean is the variable APPWRITE_FUNCTION_JWT will have the JWT Only when:
- Executed from a client side
- Executed from a server side by using JWT instead of API token

Git it
Recommended threads
- Server Error when Pushing a Function
Get this ambiguous error when trying to push my function, it's TypeScript using NodeJS 18 ``` ? Which functions would you like to push? get-grades (get-grades)...
- Hola equipo de soporte,
Hola equipo de soporte, Estoy desarrollando una Function en Appwrite Cloud con Node.js 22 y el siguiente package.json: { "name": "upload-whitelist", "type"...
- Function running in cloud but not locall...
Hi everyone, I have an appwrite function which is on python3.12 runtime. I have a library (hnswlib) which builds wheels during installation. This works on appwr...
