Not bad and bad once we have taken care of the unauthenticated error.
Next, I want to set up another instance method basically the one that is going to be on our user ID
document and the name is going to be compare password then.
Let me go back to my controller and showcase that check for the user.
If the user doesn't exist, then we throw invalid credentials before anyone.
But then if the user exists with such email, then I also want to compare the password.
So the password that is coming in with a password that is in my database and look at using the instant
method by the name of CP. password.
Now, instead of the function body will use be CryptoCompare, which returns a promise.
That's why we go here with 08 and then we're set up here, I think.
Notice how this one is looking for candidate password again.
I already said this 20000 times, but this is the one available in our request body.
So this is coming in with a request and we're checking against the one that we have in our database.
Now, one important thing to mention there is no one hashing going on.
Hashing is a one way street.
Once we hash the password storing database, that's how it's going to sit there.
What's happening here under the hood?
Be curbed?
Yes.
How is the method?
Compare where we provide the password and then essentially it sets up that hash value again and compares
whether they match.
That's the overall idea.
And in order to set everything up, we need to go to a user.
Let's keep on moving online all the way here after the Create JWT.
I also want to set up my function, my instant method by the name of comparer password.
So let's get cracking.
We're going to go with user schema and we're looking for methods more specifically.
Let's come up with the name and maker's mark.
I keep saying it's going to be a competitive password, but you can always go with vegan food truck.
I mean, functionality is going to be exactly the same in and here.
Let's go for candi date password online instead of the function body.
We're going to go with Konst is match is equal to weight.
So this returns a promise online.
Let's go with our script when the method name is compare and then we want to pass in the candidate password
and then there's that password.
And once we have all of this in place, let's go with return and is a match.
So if this is true, that means that passwords match.
So that means that we can send back the token.
If not, it's going to be false and then we throw another four or one error.
So that's how we can set up compare password as a instance method.