- [Instructor] The next step in building a secured API
is to add users that can register
and log into the application.
And for that to happen, we need a user schema.
So let's get back to VS Code,
and in the models folder, I'll create a few file.
So I'm going to go ahead and click new file here,
and then call this
user
model
dot JS.
And if you created that file outside of the folder here,
all you have to do is drag and drop that file
inside of the folder, and then yes, move it,
and then the file's going to be in the right folder.
So let's go ahead and start by importing mongoose
from mongoose.
And then, let's go ahead and create a variable
that we'll call schema.
And that looks very similar to this CR model here.
So if you don't want to waste cycles
in typing all these extra stuff,
what you can do is copy and paste that section here,
like so, and then bring it back to
the model here.
So you have the first line that we need,
and then instead of contact schema,
what we'll do is user schema.
And then we can work directly inside of that file.
So the created date is going to be there as well,
and what we're going to do is remove those two here.
So I'm going to remove company and phone.
And then reuse what we have in here
to create the new elements of a user.
So the first one is going to be username,
and it's of type string, so the same.
It is required, and what we're going to do is,
and then, what we're going to do is type true for that.
And then we're going to do email.
And again, we're going to do true.
And it's still a string, so we're good there.
And then, we're going to use hash password,
so we're going to create a field called hashpassword,
so don't forget the H.
And then for this one, is also a type string,
and then also required.
Perfect.
So what we've created here is a user schema
that we're going to leverage when we create new users.
So when we register a new user,
this is the schema that's going to check that
we have all these elements in the data
that we're passing to the server.
So username, email, and hash password.
And then, in the following video,
we're going to install bcrypt,
and then make sure that the hash password
matches the password that is passed in the data
that we're doing the request from.
So let's move on and work on that.