chore(webui): refactor login and session middleware handling

This commit is contained in:
Julien Dessaux 2025-01-14 22:24:05 -05:00
parent 1292d189cf
commit 7885b19b54
Signed by: adyxax
GPG key ID: F92E51B86E07177E
2 changed files with 9 additions and 9 deletions

View file

@ -88,9 +88,9 @@ func handleLoginPOST(db *database.DB) http.Handler {
})
}
func loginMiddleware(db *database.DB) func(http.Handler) http.Handler {
func loginMiddleware(db *database.DB, requireSession func(http.Handler) http.Handler) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
return requireSession(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store, no-cache")
session := r.Context().Value(model.SessionContextKey{})
if session == nil {
@ -110,6 +110,6 @@ func loginMiddleware(db *database.DB) func(http.Handler) http.Handler {
}
ctx := context.WithValue(r.Context(), model.AccountContextKey{}, account)
next.ServeHTTP(w, r.WithContext(ctx))
})
}))
}
}