summaryrefslogtreecommitdiff
path: root/pkg/webui
diff options
context:
space:
mode:
authorJulien Dessaux2025-01-14 22:24:05 -0500
committerJulien Dessaux2025-01-14 22:24:05 -0500
commit7885b19b543fdbe6c441efe0ffacd89fcd7f6a67 (patch)
tree5d3252264eb0c341e63eeba335b637d4461784d9 /pkg/webui
parentfeat(webui): implement logout process (diff)
downloadtfstated-7885b19b543fdbe6c441efe0ffacd89fcd7f6a67.tar.gz
tfstated-7885b19b543fdbe6c441efe0ffacd89fcd7f6a67.tar.bz2
tfstated-7885b19b543fdbe6c441efe0ffacd89fcd7f6a67.zip
chore(webui): refactor login and session middleware handling
Diffstat (limited to '')
-rw-r--r--pkg/webui/login.go6
-rw-r--r--pkg/webui/routes.go12
2 files changed, 9 insertions, 9 deletions
diff --git a/pkg/webui/login.go b/pkg/webui/login.go
index d004d82..fda227a 100644
--- a/pkg/webui/login.go
+++ b/pkg/webui/login.go
@@ -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))
- })
+ }))
}
}
diff --git a/pkg/webui/routes.go b/pkg/webui/routes.go
index 6ebe90b..e9a0346 100644
--- a/pkg/webui/routes.go
+++ b/pkg/webui/routes.go
@@ -10,12 +10,12 @@ func addRoutes(
mux *http.ServeMux,
db *database.DB,
) {
- session := sessionsMiddleware(db)
- requireLogin := loginMiddleware(db)
+ requireSession := sessionsMiddleware(db)
+ requireLogin := loginMiddleware(db, requireSession)
mux.Handle("GET /healthz", handleHealthz())
- mux.Handle("GET /login", session(handleLoginGET()))
- mux.Handle("POST /login", session(handleLoginPOST(db)))
- mux.Handle("GET /logout", session(requireLogin(handleLogoutGET(db))))
+ mux.Handle("GET /login", requireSession(handleLoginGET()))
+ mux.Handle("POST /login", requireSession(handleLoginPOST(db)))
+ mux.Handle("GET /logout", requireLogin(handleLogoutGET(db)))
mux.Handle("GET /static/", cache(http.FileServer(http.FS(staticFS))))
- mux.Handle("GET /", session(requireLogin(handleIndexGET())))
+ mux.Handle("GET /", requireLogin(handleIndexGET()))
}