Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The req.user must be accessible from within the usecase steps. #41

Closed
vitorgamer58 opened this issue Aug 20, 2022 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@vitorgamer58
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Inside my usecase, I don't have access to the req.user data, I only have access to them inside the authorize function, and most apis that use express, make use of various data that comes from within the req.user, not just from req.body.

Describe the solution you'd like
The default controller receives the req from express, and passes the req.user to the usecase authorize function, so I can make the proper assertion on the user, the req.user comes from some express middleware that was configured by the developer.
However, many express APIs use other data from req.user, like an id for example, instead of receiving the user's id in the request, it is simply received in the JWT token, and then data from the req.user is used.

For example: I have an endpoint to create accounts, I need to enter the following columns in the database: ["id", "name", "user_id"] and I expect to receive from my frontend a POST request containing only the name, the id will be created in the my usecase, but what about the user_id ? I don't want to have to receive this data in the body of the request, because it's an extra field to be configured in the frontend, and I already have the user ID in my authentication token, so, within the steps of my usecase, I want to have access to the req.user data.

Additional context
Example of an api request that makes use of req.user
https://github.com/vitorgamer58/BarrigaRest/blob/master/src/routes/accounts.js#L18

@dalssoft
Copy link
Member

dalssoft commented Sep 5, 2022

@vitorgamer58 does it make sense to keep this issue / PR after herbsjs/buchu#85 is merged ?

@vitorgamer58
Copy link
Contributor Author

@vitorgamer58 does it make sense to keep this issue / PR after herbsjs/buchu#85 is merged ?

No.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants