【发布时间】:2021-05-29 08:19:28
【问题描述】:
[开发] - 一切正常(没有问题,因为 cookie 设置在同一个域 'localhost' 上)
[PROD / LIVE] - 链接如下
问题:cookie 设置不正确或没有持久化,我不知道为什么,如果有人可以告诉我可能是什么原因,如您在网络中看到的那样选项卡,它设置了 cookie,但它没有把它放在 Application > Storage > Cookies 中,如果我解释得不是很好,你可以看看。
https://gta-open-q99pjtak6-patricksubang.vercel.app/ 用户名:demo 密码:demo
前端,POST/GET 请求
const sendRequest = async (method, endpoint, custom) => {
const isProd =
process.env.NODE_ENV === "development"
? "http://localhost:8000/"
: "https://gta-open.ga/";
const url = isProd + endpoint;
const response = await fetch(url, {
method: method,
mode: "cors",
credentials: "include",
...custom,
});
return response;
};
使用 gorrilla\sessions 设置会话 cookie
Cookie.Options.Path = "/"
Cookie.Options.HttpOnly = true
Cookie.Options.SameSite = http.SameSiteNoneMode
state := false
if os.Getenv("ENV") == "PROD" {
state = true
}
Cookie.Options.Secure = state
func GenerateSession(w http.ResponseWriter, r *http.Request, uid int) (err error) {
session, _ := Cookie.Get(r, "sessionid")
session.Values["accountID"] = uid
// Save it before we write to the response/return from the handler.
err = session.Save(r, w)
if err != nil {
return
}
return
}
如果有人可以给我一个粗略的想法,或者问题的原因会有所帮助
非常感谢!
【问题讨论】:
标签: reactjs go cookies session-cookies