fix user setting expiring immediately
This commit is contained in:
parent
238bad7dca
commit
ad0f68d705
1 changed files with 6 additions and 0 deletions
|
@ -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
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue