我有一个使用域sambat.io
的react前端,部署到Vercel (Zeit),以及部署到Heroku的Node,该域https://safe-ridge-68566.herokuapp.com/
和cookie设置如下:
res.cookie('something', 'ckwdnjwedjbdh3bhbd2hdbhbhbhfbdsf', {
httpOnly: true,
sameSite: 'none',
domain: '.sambat.io',
secure: true
})
当我访问前端时,我可以在响应中看到Set-Cookie
头,但是它不会设置cookie,并且有以下警告:
此设置-Cookie被阻塞,因为它的域属性对于当前主机url无效。
我错过了什么?
以下是网络请求和响应的详细信息:
GENERAL
Request URL: https://safe-ridge-68566.herokuapp.com/users/twitter
Request Method: POST
Status Code: 201 Created
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
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
发布于 2022-10-19 14:45:14
我也犯了同样的错误。创建cookieOptions时服务器端出现问题
var cookieOptions = new CookieOptions
{
HttpOnly = true,
Expires = DateTime.UtcNow.AddDays(7),
SameSite = SameSiteMode.None,
Secure = true,
Domain = "https://example.com" <-- problem's here
};
删除并解决问题:)
var cookieOptions = new CookieOptions
{
HttpOnly = true,
Expires = DateTime.UtcNow.AddDays(7),
SameSite = SameSiteMode.None,
Secure = true,
Domain = "example.com" <-- like this
};
https://stackoverflow.com/questions/62749492
复制相似问题