Save session for basic auth

This commit is contained in:
Teajey 2026-02-21 10:23:19 +09:00
parent 60b4fa773c
commit ab713f6662
Signed by: Teajey
GPG Key ID: 970E790FE834A713

View File

@ -1,6 +1,7 @@
package mux package mux
import ( import (
"log"
"net/http" "net/http"
"github.com/Teajey/rsvp" "github.com/Teajey/rsvp"
@ -37,6 +38,12 @@ func (m *Serve) ServeHTTP(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth() username, password, ok := r.BasicAuth()
if ok { if ok {
loggedIn := nil == routing.LoginMiddle(username, password, s, r) loggedIn := nil == routing.LoginMiddle(username, password, s, r)
if s.WasWritten() {
err := s.Save(r, w)
if err != nil {
log.Printf("Failed to save session: %s", err)
}
}
if loggedIn { if loggedIn {
m.Private.ServeHTTP(w, r) m.Private.ServeHTTP(w, r)
return return