Project Setup: Part One
Understand the project's dependencies and files before beginning to work with Passport.js.
Task 1: Install dependencies
-
Navigate to the project folder.
-
Install the following dependencies:
bcrypt
express
jsonwebtoken
passport
passport-jwt
dotenv
Press + to interact
npm install --save bcrypt express jsonwebtoken passport passport-jwt dotenv
Task 2: Set up files for user authentication routes
- In the previous chapter, we set up a
router
,controller
, andservice
for the recipes resource in the Express Recipes API. Let’s follow a similar pattern to organize our user authentication logic:
Press + to interact
touch src/routers/users.js src/services/users.js db/users.json src/controllers/users.js
- Create a new folder to store middleware functions. Within it, create a file called
auth.js
:
Press + to interact
mkdir src/middlewaretouch src/middleware/auth.js
Later on, we’ll configure the Passport.js strategy inside src/middleware/auth.js
.
- We’ll store the users’ data in
db/users.json
.
Note: This isn’t a robust database solution since there’s no built-in data validation, but it’s sufficient for demonstration purposes. ...