Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkAuthentication(req, res, next){
- if (!req.headers.authorization) {
- return res.status(401).send({ message: 'Please make sure your request has an Authorization header' });
- }
- console.log("Here");
- var token = req.headers.authorization.split('.')[1];
- console.log(token);
- console.log(config.secret);
- var payload = null;
- try {
- console.log("And here....");
- payload = jwt.decode(token, config.secret);
- console.log(payload);
- }
- catch (err) {
- console.log("NO!!!!!");
- return false;
- }
- if (payload.exp <= moment().unix()) {
- return false;
- }
- req.user = payload.sub;
- return true;
- }
- Here
- eyJzdWIiOiI1NmEyZDk3MWQwZDg2OThhMTYwYTBkM2QiLCJleHAiOjE0NTYxOTEyNzQsImlhdCI6MTQ1NTMyNzI3NH0
- VerySecretPhrase
- And here....
- NO!!!!!
- app.factory('httpInterceptor', function($q, $store, $window) {
- return {
- request: function (config){
- config.headers = config.headers || {};
- if($store.get('token')){
- var token = config.headers.Authorization = 'Bearer ' + $store.get('token');
- }
- return config;
- },
- responseError: function(response){
- if(response.status === 401 || response.status === 403) {
- $window.location.href = "http://localhost:3000/login";
- }
- return $q.reject(response);
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement