A simple user authentication with node express and mongodb .
libraries used
bcryptfor hashing the password
jsonwebtoken for storing user session
mongoose mongodb ORM
in .evn change
DATABASE=mongodb://localhost:27017/test
Note
After setting up database , .env file should be added to .gitignore file
To Run Server
yarn run server
http:localhost:3002/api/user/register
Takes req.body and saves it to database
http:localhost:3002/api/user/auth
If User is authenticated it will give you followings.
isAdmin : Boolean
isAuth: Boolean
firstName: String
lastName : String
fullName : String
http:localhost:3002/api/user/login
After checking the password it will create a token and save it as cookie
http:localhost:3002/api/user/logout
Removes the tokens