JWT Auth Strategy #33
Replies: 2 comments 3 replies
-
|
Hi @ianchikwature , could you explain me your need with a bit more details please. Medusa is using a jwt strategy and before going any further i would like to be sure to understand your needs |
Beta Was this translation helpful? Give feedback.
-
|
Hello @adrien2p, Would not this be useful in the case where an user is already logged in on the same domain with a JWT ? I would imagine something looking like this export class JWTStrategy extends PassportStrategy {
async authenticate(req, options) {
const token = req.headers.authorization?.split(' ')[1];
if (!token) {
throw new Error('No token provided');
}
try {
const decoded = jwt.verify(token, process.env.DOMAIN_WIDE_JWT_SECRET);
const userService = req.scope.resolve('userService') as UserService;
let user = await userService.retrieveByEmail(decoded.email);
if (!user) {
user = await userService.create({
email: decoded.email,
first_name: decoded.name.givenName,
last_name: decoded.name.familyName,
});
}
return { user };
} catch (error) {
throw new Error('Invalid token');
}
}
}If you think it is worth developping do not hesitate to give me a few hints on where to look so that I add this to the current plugin. As a sidenote in my case the source of the JWT is NOT capable to be a real Identity Provider and so using an Oauth2 strategy is not an option. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi @adrien2p,
Thanks for the amazing work you are doing on Medusa.
Is there a plan to add a JWT strategy? This will allow seamless integration of medusa into other systems.
Beta Was this translation helpful? Give feedback.
All reactions