gateway: set user admin value in context

This commit is contained in:
Simone Gotti 2019-05-05 17:30:38 +02:00
parent 6dfb789e77
commit 6ef5649b21
1 changed files with 11 additions and 1 deletions

View File

@ -76,6 +76,11 @@ func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// pass userid to handlers via context
ctx = context.WithValue(ctx, "userid", user.ID)
ctx = context.WithValue(ctx, "username", user.Name)
if user.Admin {
ctx = context.WithValue(ctx, "admin", true)
}
h.next.ServeHTTP(w, r.WithContext(ctx))
return
}
@ -122,9 +127,14 @@ func (h *AuthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// pass userid to handlers via context
// pass userid and username to handlers via context
ctx = context.WithValue(ctx, "userid", user.ID)
ctx = context.WithValue(ctx, "username", user.Name)
if user.Admin {
ctx = context.WithValue(ctx, "admin", true)
}
h.next.ServeHTTP(w, r.WithContext(ctx))
return
}