Guest User

Untitled

a guest
Jun 4th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. console.log('currentUser', currentUser)
  2. currentUser null
  3.  
  4. if (!currentUser) {
  5. console.log('n user not logged in');
  6. res.status(401).json('User not logged in');
  7. }
  8.  
  9. TypeError: Cannot read property 'token' of null
  10. at exports.authenticate (sandbox2nghd09backendappcontrollersuser.server.controller.js:47:40)
  11. at Layer.handle [as handle_request] (sandbox2nghd09node_modulesexpresslibrouterlayer.js:95:5)
  12.  
  13. exports.authenticate = function (req, res, next) {
  14. var headerExists = req.headers.authorization;
  15. console.log('authenticate called', headerExists)
  16. var currentUser = req.headers.authorization.split(' ')[1];
  17. console.log('currentUser', currentUser)
  18.  
  19. if (!currentUser) {
  20. console.log('n user not logged in');
  21. res.status(401).json('User not logged in');
  22. }
  23.  
  24. // if (currentUser) {
  25. var token = JSON.parse(currentUser).token;
  26. console.log('ntoken', token)
  27. jwt.verify(token, config.sessionSecret, function (err, decoded) {
  28. if (err) {
  29. console.log(err);
  30. res.status(401).json('Unauthorized');
  31. } else {
  32. req.user = decoded.username;
  33. req.password = decoded.password;
  34. next();
  35. }
  36. })
  37. // }
  38. }
  39.  
  40. if (!currentUser) {
  41. console.log('n user not logged in');
  42. res.status(401).json('User not logged in');
  43. //return next(); // should return next here to stop current function
  44. }
Add Comment
Please, Sign In to add comment