我正在使用 next-auth 在我的前端对用户进行身份验证,它设置了 HTTPOnly 和Secure
JWT cookie。
我想使用该 cookie 来验证对我的后端 API 的调用,用户将通过该 API 加载前端的内容。(用户直接从 API 获取数据,而不是通过我的前端。)
现在这一切都可以在 localhost 中正常运行,因为没有为 cookie 设置 Secure 标志。在生产中,虽然 cookie 具有 __Secure- 参数,但不会与获取请求一起发送。
这是 fetch 调用。
fetch('https://differentsubdomain.mydomain.com' + '/test', {
method: 'GET',
mode: 'cors',
credentials: 'include',
})
如何强制包含安全 cookie?或者有没有更好的方法来解决这个问题?