diff options
| author | roerick <roerick@wyo.town> | 2025-10-19 14:24:40 -0600 |
|---|---|---|
| committer | roerick <roerick@wyo.town> | 2025-10-19 14:24:40 -0600 |
| commit | 132e0fe607396123a9fc5390c8657ef145bba3c6 (patch) | |
| tree | 9a420d6f89a2de70d17bfb08789a26ccc501a9b9 /middleware/auth.go | |
| parent | a1c3883334a9c54358173ebd822a5a85036dcda6 (diff) | |
initial commit with auth working
Diffstat (limited to 'middleware/auth.go')
| -rw-r--r-- | middleware/auth.go | 17 |
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) + }) +} |
