当我从前端删除对象时,我得到一个httperrorresponse状态404:错误“ el token no es valido”
nodejs中的中间件jwt
'use strict'
var jwt = require('jwt-simple');
var moment = require('moment');
var secret = "klave";
exports.authenticated = function(req, res, next) {
// Comprobar si llega autorización
if (!req.headers.authorization) {
return res.status(403).send({
message: 'La petición no tiene la cabecera de authorization'
});
}
// Limpiar el token y quitar comillas
var token = req.headers.authorization.replace(/['"]+/g, '');
console.log(token); //line 18
try {
// Decodificar token
var payload = jwt.decode(token, secret);
// Adjuntar usuario identificado a request
// req.user = payload;
// Pasar a la acción
// next();
// Comprobar si el token ha expirado
if (payload.exp <= moment().unix()) {
return res.status(404).send({
message: 'El token ha expirado'
});
}
} catch (ex) {
return res.status(404).send({
message: 'El token no es válido'
});
}
// Adjuntar usuario identificado a request
req.user = payload;
// Pasar a la acción
next();
};
在console.log(令牌)第18行中,我得到{token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1ZjAyNWMxOGU0Y2IyMDIxYTgwNTVmZjYiLCJuYW1lIjoibWFydGEiLCJzdXJuYW1lIjoibWFydGEiLCJlbWFpbCI6Im1hcnRhQG1hcnRhLmNvbSIsInJvbGUiOiJST0xFX0FETUlOIiwiaW1hZ2UiOm51bGwsImlhdCI6MTYwMjg1MDQwM30.89vDC_PaQG733gL6aW1kV1t5HaDfPfJD-0DiyDvSUdw}
没有“”,但我必须退出{token:从令牌中仅值eyj0EXaIoIj ....... ????