From 95390ee692ff0c6c1f0d8263b8e4ba991ae9c6bb Mon Sep 17 00:00:00 2001 From: Baraa Al-Masri Date: Sun, 2 Jun 2024 13:45:12 +0300 Subject: [PATCH] fix(handlers): api's mobile context --- app/handlers/handler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/handlers/handler.go b/app/handlers/handler.go index 6d13c35..785332e 100644 --- a/app/handlers/handler.go +++ b/app/handlers/handler.go @@ -85,6 +85,7 @@ func (a *Handler) OptionalAuthApi(h http.HandlerFunc) http.HandlerFunc { return } ctx := context.WithValue(r.Context(), ProfileIdKey, profile.Id) + ctx = context.WithValue(ctx, IsMobileKey, isMobile(r)) h(w, r.WithContext(ctx)) } } @@ -97,7 +98,9 @@ func (a *Handler) AuthApi(h http.HandlerFunc) http.HandlerFunc { w.WriteHeader(http.StatusUnauthorized) return } - h(w, r.WithContext(context.WithValue(r.Context(), ProfileIdKey, profile.Id))) + ctx := context.WithValue(r.Context(), ProfileIdKey, profile.Id) + ctx = context.WithValue(ctx, IsMobileKey, isMobile(r)) + h(w, r.WithContext(ctx)) } } @@ -105,7 +108,7 @@ func (a *Handler) AuthApi(h http.HandlerFunc) http.HandlerFunc { func (a *Handler) NoAuthApi(h http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - h(w, r) + h(w, r.WithContext(context.WithValue(r.Context(), IsMobileKey, isMobile(r)))) } }