Created
October 19, 2015 16:44
-
-
Save chanakaDe/bb84dde83b2661279e0f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check logged status in order to | |
* give permission to following links. | |
*/ | |
api.use(function (req, res, next) { | |
console.log("Somebody logged into system"); | |
var token = req.body.token || req.param('token') || req.headers['x-access-token']; | |
// Check if token exists. | |
if (token) { | |
jsonwebtoken.verify(token, secretKey, function (err, decoded) { | |
if (err) { | |
res.status(403).send({success: false, message: "Failed to authenticate"}); | |
} else { | |
req.decoded = decoded; | |
next(); | |
} | |
}); | |
} else { | |
res.status(403).send({success: false, message: "No valid token provided"}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment