Add RequireUser middleware

This commit is contained in:
2024-08-29 07:03:13 -04:00
parent e32aa9ca6c
commit 530672437c
2 changed files with 29 additions and 5 deletions

View File

@@ -47,3 +47,25 @@ func (umw UserMiddleware) SetUser(next http.Handler) http.Handler {
next.ServeHTTP(w, r)
})
}
func (umw UserMiddleware) RequireUserfn(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user := User(r.Context())
if user == nil {
http.Redirect(w, r, "/signin", http.StatusFound)
return
}
next(w, r)
})
}
func (umw UserMiddleware) RequireUser(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
user := User(r.Context())
if user == nil {
http.Redirect(w, r, "/signin", http.StatusFound)
return
}
next.ServeHTTP(w, r)
})
}