Compare commits

..

No commits in common. "17cf37d4ec62050cad8a2ba696ecad252c931328" and "32256b3c0e6d11255d93d40d3f1bcbdea55c7273" have entirely different histories.

View File

@ -21,6 +21,8 @@ func (s *Server) SetCookie(ctx *gin.Context, name, value string, duration time.D
path string = "/"
httpOnly bool = false // NOTE: Should use false so React can see it!
maxAge int
secure bool = true
domain string = ""
)
if duration < 0 {
@ -34,46 +36,19 @@ func (s *Server) SetCookie(ctx *gin.Context, name, value string, duration time.D
maxAge = int(time.Until(time.Now().Add(duration)).Seconds())
}
switch s.deps.EnvironmentConfig.Environment {
case "prod":
// Cross-site between subdomains, HTTPS only
ctx.SetSameSite(http.SameSiteNoneMode)
ctx.SetCookie(
name,
value,
maxAge,
path,
".gophernest.net", // or your backend domain / parent
true, // secure
httpOnly,
)
case "dev":
// Local dev on http://localhost:PORT
ctx.SetSameSite(http.SameSiteLaxMode)
ctx.SetCookie(
name,
value,
maxAge,
path,
"", // no Domain → default to current host
false, // not secure on plain HTTP
httpOnly,
)
// TODO: This whole system is stupid now
if s.deps.EnvironmentConfig.Environment == "prod" {
secure = true
// domain = "potion.gophernest"
// domain = s.deps.EnvironmentConfig.Domain
domain = ".gophernest.net"
} else if s.deps.EnvironmentConfig.Environment == "dev" {
secure = false
// domain = s.deps.EnvironmentConfig.Domain
domain = "localhost"
}
// TODO: This whole system is stupid now
// if s.deps.EnvironmentConfig.Environment == "prod" {
// secure = true
// // domain = "potion.gophernest"
// // domain = s.deps.EnvironmentConfig.Domain
// domain = ".gophernest.net"
//
// } else if s.deps.EnvironmentConfig.Environment == "dev" {
// secure = false
// // domain = s.deps.EnvironmentConfig.Domain
// domain = "localhost"
// }
//
// ctx.SetSameSite(http.SameSiteNoneMode)
// ctx.SetCookie(name, value, maxAge, path, domain, secure, httpOnly)
ctx.SetSameSite(http.SameSiteNoneMode)
ctx.SetCookie(name, value, maxAge, path, domain, secure, httpOnly)
}