当我在Travis中运行需要JWT令牌验证的测试时,该测试失败,我从JWT代码中得到错误 但在本地测试中可以正常工作
// JWT function
import jwt from 'jsonwebtoken';
import dotenv from 'dotenv';
dotenv.config();
console.log(process.env.NODE_ENV);
module.exports = (req, res, next) => {
try {
if (process.env.NODE_ENV === undefined) {
next();
}
const decode = jwt.verify(req.body.token, process.env.JWT_KEY);
req.userData = decode;
next();
} catch (error) {
return res.status(401).json({
message: 'failed',
error: 'Invalid Request Token',
});
}
};
致电以下验证
router.get('/', verify, (req, res) => {
viewtrips().then((result) => {
res.status(200).json({
status: 'success',
result,
});
});
});
````
I get the 409 error inside the JWT in Travis
but it works well in local test