【问题标题】:I can't send cookie with express res.cookie我无法使用 express res.cookie 发送 cookie
【发布时间】:2021-01-16 06:31:08
【问题描述】:

我想发送带有 cookie 的 jwt,但在浏览器中看不到它。

这是发送 cookie 的路由:

router.post('/signup', async (req, res) => {
    const { email, password } = req.body
    try {
        const user = await User.create({ email, password })
        const token = createToken(user._id)
        res.status(201).cookie('jwt', token, { httpOnly: true, maxAge: maxAge * 1000 })
    } catch (err) {
        const errors = handleErrors(err)
        res.json({ errors })
    }
})

我在 chrome 应用程序选项卡中看不到“jwt”cookie。

我确信服务器运行良好。

我确定令牌大小小于 4kb。

我正在使用 express 4.17.1。

【问题讨论】:

    标签: javascript express cookies jwt


    【解决方案1】:

    也许this answer 可以解决您的问题。显然你需要包括

    credentials: 'include'
    

    在您的请求中指定您需要 cookie。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      • 2019-09-07
      • 2021-03-05
      • 2020-08-14
      • 2019-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多