her*_*ang 4 javascript cookies setcookie node.js express
我有一个带有 domain 的 react 前端sambat.io,部署到 Vercel (Zeit) 和一个 Node API 部署到 Heroku,具有这个域https://safe-ridge-68566.herokuapp.com/和 cookie 设置,如下所示:
res.cookie('something', 'ckwdnjwedjbdh3bhbd2hdbhbhbhfbdsf', {
httpOnly: true,
sameSite: 'none',
domain: '.sambat.io',
secure: true
})
Run Code Online (Sandbox Code Playgroud)
当我访问前端时,我可以看到Set-Cookie响应中的标头,但它不会设置 cookie 并且有以下警告:
此 Set-Cookie 被阻止,因为其域属性对于当前主机 url 无效。
我在这里错过了什么?
以下是网络请求和响应的详细信息:
GENERAL
Request URL: https://safe-ridge-68566.herokuapp.com/users/twitter
Request Method: POST
Status Code: 201 Created
Run Code Online (Sandbox Code Playgroud)
RESPONSE HEADERS
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: https://sambat.io
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Set-Cookie: something=hwjdhwjdhwjehdjwdhuhhd3hd3u; Domain=.sambat.io; Path=/; HttpOnly; Secure; SameSite=None
Vary: Origin
Run Code Online (Sandbox Code Playgroud)
REQUEST HEADERS
Accept: application/json, text/plain, */*
Connection: keep-alive
Content-Type: application/json
Cookie: something=hwjdhwjdhwjehdjwdhuhhd3hd3u
Host: safe-ridge-68566.herokuapp.com
Origin: https://sambat.io
Pragma: no-cache
Referer: https://sambat.io/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
Run Code Online (Sandbox Code Playgroud)
小智 7
我认为这个问题是因为前端和后端没有相同的域,尝试通过创建子域来尝试将后端放在同一个域上。
如果您遇到任何其他问题,请告诉我。
快乐编程。