cookie expiration as time duration.

This commit is contained in:
Miroslav Šedivý 2022-01-16 21:03:25 +01:00
parent 0dd11fc1b7
commit 646b6ecaff
2 changed files with 3 additions and 3 deletions

View File

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

View File

@ -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,