I have this middle-ware function which checks if the user is logged in or not, since I have web application and android platform as well therefore I am using tokens for the android and for web I am using session which is by default manager by passport.
In my function
I am checking If I have a Authorization header, I know it's my android platform and therefore verify user by verifying jwt token, but It is always sending me 401 unauthorized and not setting the req.user.
Here is the middle-ware function, if someone can please point out my mistake where I am going wrong in my logic.
var jwt_auth = require('express-jwt')
// route middleware to make sure a user is logged in
function isLoggedIn(req, res, next) {
if (req.get("Authorization")) {
jwt_auth({secret: 'somesecret'});
if (req.user) {
return next();
}
res.send(200, "Unauthorized access");
}
else {
// if user is authenticated in the session, carry on
if (req.isAuthenticated())
return next();
// if they aren't redirect them to the home page
res.redirect('/');
}
}
jwt
token on client side ? – Mukesh Sharma