Back

Create JWT Token for testing purposes

  • 0
  • Accounts
  • Functions
whataboutno13
18 Aug, 2023, 10:25

Hi there, I have a function which should act like a user in most ways and therefore init the client with a JWT token. Now I want to test the method, but I cannot find any way to generate a jwt token for a test user I created. Is there a way to do this? Cheers! <:appwriteheart2:1073243188954935387>

TL;DR
User wants to generate a JWT token for testing purposes. Some suggestions include using a tool from GitHub, using the JWT token automatically generated when a function is executed, or using the createJWT function in the account module. No optimal solution is provided.
otik
18 Aug, 2023, 11:10

account.createJWT() i think

otik
18 Aug, 2023, 11:11

for example you can then send this jwt in headers

whataboutno13
18 Aug, 2023, 12:51

Yes, but I am not testing the function from client side. So there is no option to create a JWT Token there

Binyamin
18 Aug, 2023, 13:09

There is none You'll need to use the createJWT to generate the JWT, then use it in the test. You can use Postman for generating the JWT after log in the user.

whataboutno13
18 Aug, 2023, 14:01

Mhh this does not seem like an optimal solution, but I'll take it

Binyamin
18 Aug, 2023, 14:02

If you need it for more then tests

Binyamin
18 Aug, 2023, 14:02

There is another approach

Drake
18 Aug, 2023, 15:52

when an end user executes a function, the function automatically has a JWT token set that can be used to make requests on behalf of the user...why not use that?

whataboutno13
18 Aug, 2023, 16:11

Theoretically yes, therefore I would have to use the client to test the function correct? Because I wanted to do it locally and therefore would have to go the way @Binyamin mentioned and generate a jwt token manually.

Drake
18 Aug, 2023, 16:14

you can just create a session and then execute the function. i don't think you need the extra step of creating a jwt token. maybe you can use this tool: https://github.com/stnguyen90/appwrite-explorer

whataboutno13
21 Aug, 2023, 06:54

Alright I'll try that, thanks @Steven & @Binyamin :appwriteheart2:

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