summaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
authorroerick <roerick@wyo.town>2025-10-19 14:24:40 -0600
committerroerick <roerick@wyo.town>2025-10-19 14:24:40 -0600
commit132e0fe607396123a9fc5390c8657ef145bba3c6 (patch)
tree9a420d6f89a2de70d17bfb08789a26ccc501a9b9 /middleware
parenta1c3883334a9c54358173ebd822a5a85036dcda6 (diff)
initial commit with auth working
Diffstat (limited to 'middleware')
-rw-r--r--middleware/auth.go17
1 files changed, 17 insertions, 0 deletions
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)
+ })
+}