Dave Gray ownership
This repo is a copy of a repo from Dave Gray
Your can find the source here
✅ Check out the Dave's Gray YouTube Channel with all of his tutorials.
This repository shares the code applied during a Youtube tutorial made by Dave Gray. To complete the challenge, you can complete the tutorial here: JWT Authentification in an Express app.
The mission:
We gevi you a pre-made code. It's a simple application made with Express and an architecture MVC (Model-View-Controller). This app stores users in a json file. The users are able to connect to the app via a password. But we would like to add a security layer.
So the goal is to implement a JWT authorization.
Your implementation should use the jsonwebtoken NPM package, specifically the sign()
and verify()
method.
- Create a strong secret key, and put it in an gitignored
.env
file - Create a
POST
route in which you can connect to the with an user. Inside that route create a token using theJWT.sign
method, that contains the username, a passsword, and sign it using your secret key. - Create a middleware to validate the token, using the
JWT.verify
method. - Create a token-protected route by using your middleware. To access this route the user should add their token in their
Authorization
request header.
use the app:
Install packages: npm install
Run the server: npm run dev
The routes :
- The homepage:
localhost:3500/
- Register a user:
localhost:3500/register
- Login:
localhost:3500/auth
Avoid plagiargism and adhere to the spirit of this Academic Honesty Policy.