Hello,
I AWS Cognito for login on the frontend and I want to now issue JWT tokens for the associated Strapi user once they login. I recieve the id_token back from OAuth backend and decode it to get that user’s email address. With that email address, I lookup the user or create the user if they don’t exist:
async function findOrCreateStrapiUser(email) {
let user = await strapi.query(‘plugin::users-permissions.user’).findOne({ where: { email } });
if (!user) {
user = await strapi.query(‘plugin::users-permissions.user’).create({
data: {
username: email,
email,
provider: ‘cognito’,
confirmed: true
}
});
}
return user;
}
And now that I have the user, I try to issue the JWT token:
async function generateStrapiJwt(user) {
const jwtService = strapi.plugin(‘users-permissions’).services.jwt;
const token = jwtService.issue({ id: user.id });
return token;
}
My problem is, once I have the token above, I am not able to use it to authorize subsequent API calls (I’m just attempting to hit /api/user/me with that token as the Bearer token
Appreciate any help you can provide
This topic has been created from a Discord post (1275163629376765962) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord