summaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
Diffstat (limited to 'middleware')
-rw-r--r--middleware/auth.go7
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)
})
}
+
+