From 659c8dbbecb0800593b9275351c10801fa9fba55 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Fri, 9 May 2025 08:01:25 +0300 Subject: [PATCH] Enha: cookies for local dev --- config/config.go | 4 +++- handlers/auth.go | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 39f776e..f15b65e 100644 --- a/config/config.go +++ b/config/config.go @@ -28,8 +28,10 @@ func LoadConfigOrDefault(fn string) *Config { if err != nil { slog.Warn("failed to read config from file, loading default", "error", err) config.BaseURL = "https://localhost:3000" - config.SessionLifetime = 300 + config.SessionLifetime = 30000 config.CookieSecret = "test" + config.ServerConfig.Host = "localhost" + config.ServerConfig.Port = "3000" } return config } diff --git a/handlers/auth.go b/handlers/auth.go index f12864c..0a3ac6d 100644 --- a/handlers/auth.go +++ b/handlers/auth.go @@ -105,9 +105,9 @@ func makeCookie(username string, remote string) (*http.Cookie, error) { cookieValue := base64.URLEncoding.EncodeToString([]byte( string(signature) + sessionToken)) cookie := &http.Cookie{ - Name: cookieName, - Value: cookieValue, - Secure: true, + Name: cookieName, + Value: cookieValue, + // Secure: true, HttpOnly: true, SameSite: http.SameSiteNoneMode, Domain: cfg.ServerConfig.Host, @@ -115,7 +115,9 @@ func makeCookie(username string, remote string) (*http.Cookie, error) { log.Info("check remote addr for cookie set", "remote", remote, "session", session) if strings.Contains(remote, "192.168.0") { - cookie.Domain = "home.host" + // cookie.Domain = "192.168.0.101" + cookie.Domain = "" + cookie.SameSite = http.SameSiteLaxMode log.Info("changing cookie domain", "domain", cookie.Domain) } // set ctx?