Fix session bumping
This commit is contained in:
1 parent
3864a4c1cc
commit
feaab7e4e2
2 files changed
+5
-2
No files matched your search
@@ -9,7 +9,7 @@ import (
|
|||||||
const UserKey = "user"
|
const UserKey = "user"
|
||||||
const SessionKey = "session"
|
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 func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
cookie, err := r.Cookie(sessionCookieName)
|
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)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
return
|
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(r.Context(), UserKey, user)
|
||||||
ctx = context.WithValue(ctx, SessionKey, newSession)
|
ctx = context.WithValue(ctx, SessionKey, newSession)
|
||||||
|
|||||||
@@ -228,5 +228,5 @@ func (h *Handler) Serve(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) sessionMiddleware() middleware.Middleware {
|
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)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user