- passport
- passport-jwt
- jsonwebtoken
- bcryptjs
- PostgreSQL
- pg-promise
- bluebird
To register a new user:
POST /users/new
To login (receive a token in the response):
POST /users/authenticate
In request, send "Authorization" Header with the token to:
GET /users/profile
Use this in your route to authenticate any request:
router.get('/[endpoint]', passport.authenticate('jwt', { session: false }), (req, res, next) => {
// IF YOU GET HERE, IT MEANS THE TOKEN IS AUTHENTICATED
// DO SOMETHING
});
- Json Web Token: https://github.com/auth0/node-jsonwebtoken
- Passport-JWT: https://github.com/themikenicholson/passport-jwt
- Passport: https://github.com/jaredhanson/passport
- Git clone this project
- Open up Terminal or Command line
- Navigate to the directory where the project was cloned to
- Run this command: psql -f ./config/db/schema.sql
- This command will create a PostgreSQL database along with the tables
- Setup environment variables:
- Create .env file in your project root with these two variables
DATABASE_URL=postgres://localhost:5432/userauth_app
SECRET_KEY=38219ejhhsd@#$%$@^$#%Cdviroirer
- To run the application, you need to install the dependencies, run this command: npm install --save
- To start the application, run this command: npm start
- The application will run at: localhost:3000, if that port is already in use, run this command: PORT=1738 npm start
- This command will start the server at: localhost:1738