diff options
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) + }) +} |
