From 6ef5649b21fb2e81b1c06a310aa6100214ec430d Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Sun, 5 May 2019 17:30:38 +0200 Subject: [PATCH] gateway: set user admin value in context --- internal/services/gateway/handlers/auth.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/services/gateway/handlers/auth.go b/internal/services/gateway/handlers/auth.go index 0996317..d40cec2 100644 --- a/internal/services/gateway/handlers/auth.go +++ b/internal/services/gateway/handlers/auth.go @@ -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 }