fix user setting expiring immediately

This commit is contained in:
partisan 2024-08-21 11:08:37 +02:00
parent 3b4b9ee83a
commit a7e1ef812e

View file

@ -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
})