All right.
And in order to complete our register controller, we need to figure out what we're doing with a password
because at the moment we're sending it back to the front end, which is not something that we want to
do.
And essentially, we have multiple approaches.
And one of them is in the schema where in the Mongoose we can actually use select property and notice
if it's true, the path should always be included in the results.
But if it's false, then it's going to be excluded by default.
And what's really cool is that we can override this on a query level, so essentially notice you're
able to select true or false.
And then when you're setting the query, you can say, Hey, listen, I know that I set up this property
to be excluded or included.
And actually, I want to include that in the query, and I'll show you in our project as well so where
you'll have a better understanding?
Now here's the gotcha, though, since we use user not create, it is not going to work.
So let me showcase that first.
When I want to do is go to use their dash and then where I have the password, I'm going to go with
select and I'll serve equal to force.
So I don't want to share that.
For example, if I'm going to use find one, then password will be excluded.
However, in this case, like I just mentioned, since we're using user create, we'll still get back
the password and I know that some people might find this annoying.
But let me showcase that where essentially everything is saved here, everything works properly.
And then once I send, yep, I still have the password.
So in this case, we have two options.
We can create utils folder and just create a function that gets me the powers that I'm looking for.
Effectively, what I want to get is email, last name, location and name that's going to be set up
here in this user object or in this case, I can just them now since in the login and update, user
will use different methods.
So we're not going to use, create and effectively.
By doing so, we won't get back to password, which is exactly what I'm looking for.
In this case.
I'll just add code again.
If there's multiple places where you need to do that, it kind of makes sense to set up the function.
So in this case, here's what I want to do.
I simply want to go with the user that's going to be my object, and I'll say email is equal to use
their email than the last name will be equal to what we'll well, user.
And then that and last name, correct?
So that's what we're sending back and we want to do the same thing with location.
That's going to be user and location.
And then lastly, you can probably already guess that we're going to be looking for name and user not
name.
Again, I fully understand that you're looking at this location here and like, What is wrong with you,
man?
Why are doing this?
Trust me, once we get to this point on the front end, you'll see why we're doing these acrobatics.
So, yes, the select force works really nicely, but not with this particular dart create.
So let me navigate quickly back to my database.
Let me remove the John one more time, and then let's try it out where in our response, we should get
the properties that we just set up in the user object.
So let me send it.
And what do you know?
I have email, last name, location and there not much is exactly what I was setting up over here.
And with this in place now, we can move on to our next step.