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: user.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
1 Like
It worked!
Thank you very much Andrey, it helped me a lot!
1 Like
I’m trying to work with this implementation now in Strapi v4, as I want to access the Strapi API from another strapi service and I can’t find any other way to do so (I want to upload images in a corn job… and that is way more difficult than expected).
Unfortunately, I can’t get it working. The function is creating some kind of JWT, but it is not a valid JWT.