Replies: 1 comment
-
Take a look at this blog post: http://thecodebarbarian.com/thoughts-on-user-passwords-in-rest-apis.html TLDR; generally best to store passwords in a separate |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the following schema:
And inside the first middleware in my Express app, I have the following code:
Now I am in the 30nth middleware in the stack, and I finally want to send the response, but when I simply write
It sends the response with the
password_createTime
field, which should not be visible because this field must be hidden (because of the context ofselect: false
property in the schema).I have many other routes on the API, that depend on this
req.loggedInUser
property, which is getting set by the first middleware in the stack.The problem is that some routes on the API modify the
req.loggedInUser
to change other fields, for instance, the [PATCH /users/me] route is used to update the profile of the user such as thename
field, then it uses the.save()
method to save the new document. which means that I can't setuserDoc.password_createTime = undefined
because it's a 👎 bad practice, it will be sent to the database as undefined, just because I wanted to remove it from the response.Now. The question is: I want to remove the
password_createTime
from all the responses from anywhere in my app without having to worry about it.How can I do that?
Is there something in mongoose like:
where I can use it in my code of my first middleware like:
??
By The way, I was reading this, but I believe that most of the answers here are "bad practices":
Beta Was this translation helpful? Give feedback.
All reactions