DigitMagazine

Server Middleware

Mar 23rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. module.exports = (req, resp, next) => {
  2. "use strict";
  3. let userToken = req.header('x-access-token');
  4. if (!userToken) {
  5. return resp.status(HTTPStatus.UNAUTHORIZED).send({
  6. "status": "error",
  7. "message": "Unauthorized Access"
  8. });
  9. }
  10. jwt.verify(userToken, appConfig.APP_SECRET, (err, decoded) => {
  11. if (err) {
  12. return resp.status(HTTPStatus.INTERNAL_SERVER_ERROR).send({
  13. "status": "error",
  14. "message": "Unable To Verify User Token"
  15. });
  16. }
  17. req.body.userID = decoded;
  18. next();
  19. });
  20. };
Add Comment
Please, Sign In to add comment