Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function checkAuthentication(req, res, next){
  2. if (!req.headers.authorization) {
  3. return res.status(401).send({ message: 'Please make sure your request has an Authorization header' });
  4. }
  5. console.log("Here");
  6. var token = req.headers.authorization.split('.')[1];
  7. console.log(token);
  8. console.log(config.secret);
  9. var payload = null;
  10. try {
  11. console.log("And here....");
  12. payload = jwt.decode(token, config.secret);
  13. console.log(payload);
  14. }
  15. catch (err) {
  16. console.log("NO!!!!!");
  17. return false;
  18. }
  19.  
  20. if (payload.exp <= moment().unix()) {
  21. return false;
  22. }
  23. req.user = payload.sub;
  24. return true;
  25. }
  26.  
  27. Here
  28. eyJzdWIiOiI1NmEyZDk3MWQwZDg2OThhMTYwYTBkM2QiLCJleHAiOjE0NTYxOTEyNzQsImlhdCI6MTQ1NTMyNzI3NH0
  29. VerySecretPhrase
  30. And here....
  31. NO!!!!!
  32.  
  33. app.factory('httpInterceptor', function($q, $store, $window) {
  34. return {
  35. request: function (config){
  36. config.headers = config.headers || {};
  37. if($store.get('token')){
  38. var token = config.headers.Authorization = 'Bearer ' + $store.get('token');
  39. }
  40. return config;
  41. },
  42. responseError: function(response){
  43. if(response.status === 401 || response.status === 403) {
  44. $window.location.href = "http://localhost:3000/login";
  45. }
  46. return $q.reject(response);
  47. }
  48. };
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement