How to generate JWT for customised endpoits?

Hello, I hope you are all well

I know I’m probably asking a silly question but I’m new to strapi and the solutions I’ve found and tried from forums haven’t worked for me.

I am writing some custom endpoints in user-permissions and I would like to send jwt in those endpoints to improve the security of my application.

This is how I am implementing it:

const jwtToken = await strapi.service(‘plugin::users-permissions.jwt’).issue({ id: });
ctx.response.body= {
jwt: jwtToken,
data: user

Adding these lines and testing the endpoint gives me a 403.

Hello. This code works in my project
1 create jwt token

const jwtToken = strapi.plugins['users-permissions'].services.jwt.issue({
  id: userId

2 Set endpoints in admin panel for Authenticated users

3 Set Authorization header

It worked!

Thank you very much Andrey, it helped me a lot!

1 Like