Skip to content

Commit

Permalink
fix(handlers): api's mobile context
Browse files Browse the repository at this point in the history
  • Loading branch information
mbaraa committed Jun 2, 2024
1 parent d054a9e commit 95390ee
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/handlers/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand All @@ -97,15 +98,17 @@ 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))
}
}

// NoAuthApi returns a page's handler after setting Content-Type to application/json.
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))))
}
}

Expand Down

0 comments on commit 95390ee

Please sign in to comment.