diff options
| author | roerick <roerick@wyo.town> | 2025-10-19 15:50:47 -0600 |
|---|---|---|
| committer | roerick <roerick@wyo.town> | 2025-10-19 15:50:47 -0600 |
| commit | 56b77ad18c90e47299c46d6f0fde8abe3ff6d16d (patch) | |
| tree | 906dc5417e2c81e4c28af326c1e5d73e1b7d7776 /middleware/auth.go | |
| parent | 132e0fe607396123a9fc5390c8657ef145bba3c6 (diff) | |
switch to mux prefix for router
Diffstat (limited to 'middleware/auth.go')
| -rw-r--r-- | middleware/auth.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/middleware/auth.go b/middleware/auth.go index 947985a..a42d59c 100644 --- a/middleware/auth.go +++ b/middleware/auth.go @@ -2,16 +2,21 @@ package middleware import ( "net/http" + "net/url" "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) + nextURL := url.QueryEscape(r.URL.RequestURI()) + http.Redirect(w, r, "/login?next="+nextURL, http.StatusFound) return } next.ServeHTTP(w, r) }) } + + |
