diff --git a/user-settings.go b/user-settings.go index 9b7b5ee..8056287 100755 --- a/user-settings.go +++ b/user-settings.go @@ -3,6 +3,7 @@ package main import ( "html/template" "net/http" + "time" ) type UserSettings struct { @@ -39,10 +40,13 @@ func loadUserSettings(r *http.Request) UserSettings { } func saveUserSettings(w http.ResponseWriter, settings UserSettings) { + expiration := time.Now().Add(90 * 24 * time.Hour) // 90 days from now + http.SetCookie(w, &http.Cookie{ Name: "theme", Value: settings.Theme, Path: "/", + Expires: expiration, // Expiration time needs to be set otherwise it will expire immediately Secure: true, // Ensure cookie is sent over HTTPS only SameSite: http.SameSiteNoneMode, // Set SameSite to None }) @@ -50,6 +54,7 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) { Name: "language", Value: settings.Language, Path: "/", + Expires: expiration, Secure: true, // Ensure cookie is sent over HTTPS only SameSite: http.SameSiteNoneMode, // Set SameSite to None }) @@ -57,6 +62,7 @@ func saveUserSettings(w http.ResponseWriter, settings UserSettings) { Name: "safe", Value: settings.SafeSearch, Path: "/", + Expires: expiration, Secure: true, // Ensure cookie is sent over HTTPS only SameSite: http.SameSiteNoneMode, // Set SameSite to None })