3
0
corteza/pkg/auth/middleware.go
2020-11-04 14:18:33 +01:00

21 lines
390 B
Go

package auth
import (
"errors"
"github.com/cortezaproject/corteza-server/pkg/api"
"net/http"
)
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() {
api.Send(w, r, errors.New("Unauthorized"))
return
}
next.ServeHTTP(w, r)
})
}