我需要在nodeJS中调用此api。
app.post('/api/v1/client', (req, res) => {
passport.authenticate('jwt', {session: false}, (err, user, info) => {
if (!user && !req.isAuthenticated()) {
return res.status(400).send(new Error(400));
}
return res.status(200).send("OK")
})(req, res);
});
这是我接到电话的地方。
app.post('/add_client', (req,res) => {
var options = {
url: config.DOMAIN + '/api/v1/client,
method: 'POST',
json: true,
headers: {
'Content-Type': 'application/json'
},
body: {
"name": req.body.name,
"surname": req.body.surname,
"notes": req.body.notes
}
};
request.post(options, function (error, response, body) {
if (response.statusCode == 200)
req.flash('ok_msg', 'OK');
else
req.flash('error_msg', 'ERROR.');
});
});
req.isAuthenticated()不正确,因此调用返回400。
没有嵌套请求的req.isAuthenticated()可以正常工作,我认为这是因为我没有将通行证会话/ cookie传递给嵌套请求。
那么,如何将这些东西传递给嵌套请求?
谢谢!