From the course: Node.js: Securing RESTful APIs

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add the handlers for loginRequired

Add the handlers for loginRequired

From the course: Node.js: Securing RESTful APIs

Start my 1-month free trial

Add the handlers for loginRequired

- [Instructor] Okay, so let's go ahead and create the controllers for our user model. So in the controllers folder, go ahead and click new file, and we're going to call this usercontrollers.js, and then we're going to import a few things. So first, we're going to import mongoose from mongoose. And then we'll import bcrypt from bcrypt. We'll also import JWT, which we'll need soon from jsonwebtoken, which we've installed previously. And then we'll also import the user's key mod that we just created. Again, the tip that I gave you earlier will work in this case, so let's go ahead and do from models, and usermodel, and then, if I go ahead and start typing what are the exports available for me, like userschema, it's going to suggest that, which is a neat trick inside of VS Code. All right, so let's go ahead and create a variable that we'll call User, and I want to do capital U. We're going to create a model from…

Contents