Skip to content

Conversation

@sjvans
Copy link
Contributor

@sjvans sjvans commented Dec 3, 2024

re #1483

@sjvans sjvans marked this pull request as ready for review December 3, 2024 13:05
@sjvans sjvans requested a review from smahati as a code owner December 3, 2024 13:05
@sjvans sjvans mentioned this pull request Dec 3, 2024
::: tip
Please note the difference between `req` in a service handler (instance of `cds.EventContext`) and `req` in an express middleware (instance of `http.IncomingMessage`).
Case in point, `req.user` in a service handler is an official API and, if not explicitely set, points to `cds.context.user`.
On the other hand, setting `req.user` in a custom authentication middleware is deprecated.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you generally discourage the use use of req.user in middleware or only for setting properties?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do recommend the usage of <cds.Request>.user or cds.context.user.

Our authentication middlewares only set cds.context.user which later on is also used when constructing a cds.Request.

<express.Request>.user is not set by us but if custom authentication middlewares set it, it's still working but deprecated. Custom authentication middlewares should also set cds.context.user instead.

@sjvans sjvans added this pull request to the merge queue Dec 20, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 20, 2024
@sjvans sjvans enabled auto-merge December 20, 2024 09:37
@sjvans sjvans added this pull request to the merge queue Jan 8, 2025
Merged via the queue into main with commit ac9a926 Jan 8, 2025
4 checks passed
@sjvans sjvans deleted the req.user-vs-req.user branch January 8, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants