Update service/service.go, middleware/http_middleware.go
This commit is contained in:
parent
90bee733e8
commit
583c80b799
@ -94,19 +94,20 @@ func (mw *Middleware) MiddlewareJwt(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var token, role string
|
||||
|
||||
fmt.Println("HOOOOOST", r.Host)
|
||||
switch r.Host {
|
||||
case "admin.pena.digital":
|
||||
role = "admin"
|
||||
default:
|
||||
role = "user"
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), jwt_adapter.RoleKey, role)
|
||||
|
||||
tokenCookie, err := r.Cookie(jwt_adapter.DefaultHeaderKey)
|
||||
if err != nil {
|
||||
// Escape GET requests
|
||||
if r.Method == http.MethodGet {
|
||||
next.ServeHTTP(w, r)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
return
|
||||
}
|
||||
if len(r.Header[jwt_adapter.DefaultHeaderKey]) <= 0 {
|
||||
@ -135,7 +136,7 @@ func (mw *Middleware) MiddlewareJwt(next http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.WithValue(r.Context(), jwt_adapter.DefaultHeaderKey, adapter), jwt_adapter.RoleKey, role)
|
||||
ctx = context.WithValue(ctx, jwt_adapter.DefaultHeaderKey, adapter)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
@ -439,7 +439,6 @@ func (h *Heruvym) Subscribe(ctx context.Context) chan interface{} {
|
||||
ticket, err := h.dal.GetTicket4User(ctx, ticketID, sess.Id)
|
||||
if err != nil || ticket == nil {
|
||||
output <- errors.New("no tickets 4 user")
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.dal.YieldMessages(ctx, ticketID, func(message model.Message) error {
|
||||
|
Loading…
Reference in New Issue
Block a user