我在localhost:3000上有一个Web服务器,在localhost:3001上有一个Express服务器。 在3001年,我有带有快速会话的PassportJS。当用户转到http://localhost:3001/auth/github时,它与github连接,然后将其重定向到http://localhost:3000。在localhost:3001端,如果将GET发送到/ test,则打印req.user,但是如果我对localhost:3001 / test req.user执行GET,则从localhost:3000进行定义。有什么问题?谢谢!
:3001
app.get('/auth/github/callback',
passport.authenticate('github', {failureRedirect: '/'}),
(req, res) => {
// Successful authentication, redirect home.
console.log('success')
req.session.user = req.user
res.redirect('http://localhost:3000/')
}
)
app.get('/test', (req, res) => {
console.log(req.user) //<- here it's undefined from :3000
res.json({msg: 'test'})
})
:3000
fetch('http://localhost:3001/test', {
method: 'GET',
mode: 'cors',
headers: {
'Access-Control-Allow-Origin': '*'
},
})
.then((res) => {
console.log(res)
})