node.js - 当我以角度删除对象时,令牌在nodejs中无效
问题描述
当我从前端删除一个对象时,我得到一个 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(token) 第 18 行我得到{token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1ZjAyNWMxOGU0Y2IyMDIxYTgwNTVmZjYiLCJuYW1lIjoibWFydGEiLCJzdXJuYW1lIjoibWFydGEiLCJlbWFpbCI6Im1hcnRhQG1hcnRhLmNvbSIsInJvbGUiOiJST0xFX0FETUlOIiwiaW1hZ2UiOm51bGwsImlhdCI6MTYwMjg1MDQwM30.89vDC_PaQG733gL6aW1kV1t5HaDfPfJD-0DiyDvSUdw}
没有“”但我必须从令牌中退出 { token: 只有值 eyj0EXaIoIj.......????
解决方案
推荐阅读
- database - 检查某个数据库条目是否已存在于 DIesel/Rust 中
- actionscript-3 - 使用 actionscript 执行跨域请求的不一致
- sql - 在 spring data jpa 存储库中搜索许多可选参数
- java - 如何在 Java 中使用 drawString() 绘制任何文本
- visual-studio - 使用 Visual Studio 搜索 RDL 文件
- r - 如何使用ggplot在x轴上只显示年份
- apache - 为什么 MAMP 不能启动 apache 服务器?
- vba - 打开网站时出现自动化错误
- java - 我需要显示一些我保存在房间数据库中的数据。我忘记添加到代码中或缺少什么?
- visual-studio-code - 在使用 Visual Studio 代码和在 Apache Royale 上使用 AMF 时如何在 Chrome 上禁用 CORS