3
0
corteza/pkg/auth/middleware.go
2019-10-01 17:47:43 +02:00

22 lines
382 B
Go

package auth
import (
"errors"
"net/http"
"github.com/titpetric/factory/resputil"
)
func MiddlewareValidOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var ctx = r.Context()
if !GetIdentityFromContext(ctx).Valid() {
resputil.JSON(w, errors.New("Unauthorized"))
return
}
next.ServeHTTP(w, r)
})
}