From 646b6ecaff54555ec83f7937d0699085b1533d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 16 Jan 2022 21:03:25 +0100 Subject: [PATCH] cookie expiration as time duration. --- internal/config/session.go | 4 ++-- internal/session/auth.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/config/session.go b/internal/config/session.go index 0b3454fa..990ca129 100644 --- a/internal/config/session.go +++ b/internal/config/session.go @@ -15,7 +15,7 @@ type Session struct { CookieEnabled bool CookieName string - CookieExpiration time.Time + CookieExpiration time.Duration CookieSecure bool } @@ -72,6 +72,6 @@ func (s *Session) Set() { s.CookieEnabled = viper.GetBool("session.cookie.enabled") s.CookieName = viper.GetString("session.cookie.name") - s.CookieExpiration = time.Now().Add(time.Duration(viper.GetInt("session.cookie.expiration")) * time.Hour) + s.CookieExpiration = time.Duration(viper.GetInt("session.cookie.expiration")) * time.Hour s.CookieSecure = viper.GetBool("session.cookie.secure") } diff --git a/internal/session/auth.go b/internal/session/auth.go index 06c40d6d..cc3be871 100644 --- a/internal/session/auth.go +++ b/internal/session/auth.go @@ -18,7 +18,7 @@ func (manager *SessionManagerCtx) CookieSetToken(w http.ResponseWriter, token st http.SetCookie(w, &http.Cookie{ Name: manager.config.CookieName, Value: token, - Expires: manager.config.CookieExpiration, + Expires: time.Now().Add(manager.config.CookieExpiration), Secure: manager.config.CookieSecure, SameSite: sameSite, HttpOnly: true,