Man*_*r S 6 cookies heroku setcookie node.js express
我在 Heroku 中托管了前端和后端。
我正在尝试实施谷歌身份验证。从 Google OAuth2 获取令牌后,我尝试id_token通过 Express 应用程序在 cookie 中设置 和用户详细信息。
下面是我在后端的一段代码,
authRouter.get('/token', async (req, res) => {
try {
const result = await getToken(String(req.query.code))
const { id_token, userId, name, exp } = result;
const cookieConfig = { domain: '.herokuapp.com', expires: new Date(exp * 1000), secure: true }
res.status(201)
.cookie('auth_token', id_token, {
httpOnly: true,
...cookieConfig
})
.cookie('user_id', userId, cookieConfig)
.cookie('user_name', name, cookieConfig)
.send("Login succeeded")
} catch (err) {
res.status(401).send("Login failed");
}
});
Run Code Online (Sandbox Code Playgroud)
它在我的本地设备上工作得很好,但在 Heroku 上却不起作用。
这些是我已经尝试过的域 - .herokuapp.com herokuapp.com. 另外,我尝试了不指定域字段本身的情况。
我可以看到Set-Cookie响应标头的详细信息,但 /token 端点失败,没有返回任何状态代码,并且我看不到应用程序选项卡上设置的 cookie。
请看下面的图片,
我在这里看不到任何状态代码,但它表示失败。
这些是我可以看到的 cookie 信息,但如果我通过应用程序选项卡检查,则该信息不可用。

我在这里缺少什么?有人可以帮助我吗?
| 归档时间: |
|
| 查看次数: |
3828 次 |
| 最近记录: |