Add RequireUser middleware
This commit is contained in:
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user