Fix session bumping

This commit is contained in:
blankhex committed 2026-10-23 09:31:39 +03:00
1 parent 3864a4c1cc
commit feaab7e4e2
2 files changed
+5 -2

No files matched your search

+4 -1
View File
@@ -9,7 +9,7 @@ import (
const UserKey = "user"
const SessionKey = "session"
func (s *Service) NewMiddleware(sessionCookieName string) func(http.Handler) http.Handler {
func (s *Service) NewMiddleware(sessionCookieName string, isSecure bool) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie(sessionCookieName)
@@ -40,6 +40,9 @@ func (s *Service) NewMiddleware(sessionCookieName string) func(http.Handler) htt
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
if newSession.ExpiresAt.After(session.ExpiresAt) {
SigninSetup(w, sessionCookieName, newSession.Token, newSession.ExpiresAt, isSecure)
}
ctx := context.WithValue(r.Context(), UserKey, user)
ctx = context.WithValue(ctx, SessionKey, newSession)
+1 -1
View File
@@ -228,5 +228,5 @@ func (h *Handler) Serve(ctx context.Context) error {
}
func (h *Handler) sessionMiddleware() middleware.Middleware {
return h.sessions.NewMiddleware(h.cfg.Cookies.SessionName)
return h.sessions.NewMiddleware(h.cfg.Cookies.SessionName, h.cfg.Cookies.Secure)
}