-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changed userRecommendations api to public #252
base: dev
Are you sure you want to change the base?
changed userRecommendations api to public #252
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is part of a stack:
|
Change-Id: I6965296e6f9281a8516ecbe7449d71ca9c406b65
ec845ae
to
d41a190
Compare
); | ||
router.get('/userRecommendations', (req, res, next) => { | ||
passport.authenticate('jwt', { session: false }, (err, user) => { | ||
if (err || !user) return next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have return next()
if no user and just calling next()
when there is a user, shouldn't it be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we don't need to check for a user and assign it to req.user. That it already done when we do passport.authenticate(). Thats why in lot of the controller methods, we are already using req.user.
Basically, i think you can keep the code as it was before and just remove the util.checkRole....
line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikhil-g777,
passport.authenticate()
is doing the JWT check. So, if it cannot find the user, it throws the default error 'unauthorized' and due to this default behavior, We cannot do further functionalities.
So, basically what we are doing is:
- Check if a user is available, if not available then normally move to the next middleware.
- If the user is available and is a userType mentee then add the user to the
req
object and move to the next middleware. - If the user is available and is a userType mentor then return the error 'unauthorized'.
Change-Id: I6965296e6f9281a8516ecbe7449d71ca9c406b65