Skip to content

Commit

Permalink
Pass User type in context, not its pointer
Browse files Browse the repository at this point in the history
Without this, the pointer to types.User is passed to the context.
This is a problem, as we do interface conversion.

I fixed it by ensuring we pass values instead of changing the
expected type at dest.
  • Loading branch information
evrardjp-cagip committed Jan 13, 2025
1 parent aed0e76 commit f327384
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/middlewares/httpauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func WithBasicAuth(authenticator Authenticator, next http.HandlerFunc) http.Hand
return
}

ctx := context.WithValue(r.Context(), UserContextKey, user) // This is ugly, but at least it cleans up the code and matches the usual patterns.
ctx := context.WithValue(r.Context(), UserContextKey, *user) // Store the user value directly in the context.
next.ServeHTTP(w, r.WithContext(ctx))
return
}
Expand Down

0 comments on commit f327384

Please sign in to comment.