From 132e0fe607396123a9fc5390c8657ef145bba3c6 Mon Sep 17 00:00:00 2001 From: roerick Date: Sun, 19 Oct 2025 14:24:40 -0600 Subject: initial commit with auth working --- middleware/auth.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 middleware/auth.go (limited to 'middleware/auth.go') diff --git a/middleware/auth.go b/middleware/auth.go new file mode 100644 index 0000000..947985a --- /dev/null +++ b/middleware/auth.go @@ -0,0 +1,17 @@ +package middleware + +import ( + "net/http" + + "wyo.town/netzah/session" +) + +func RequireAuth(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if !session.Manager.Exists(r.Context(), "user") { + http.Redirect(w, r, "/login", http.StatusFound) + return + } + next.ServeHTTP(w, r) + }) +} -- cgit v1.2.3