PassportJS + JWT + ServerJs
NOTE: requires MongoDB up and running
# Clone repo
git clone https://github.com/frenchbread/server.js-auth-example.git && cd server.js-auth-example
# Install dependencies
yarn install
# or
npm install
# Start server
node server.js
POST
- /register
curl -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]","password":"somepassword"}' http://localhost:3030/register
# Server reply
{"ok":true,"message":"Successfully created new user."}
POST
- /login
curl -H "Content-Type: application/json" -X POST -d '{"email":"[email protected]","password":"somepassword"}' http://localhost:3030/login
# Server reply
{"ok":true,"data":{"user":{"_id":"5a0129ec1cc973ec2e92b985","email":"[email protected]"},"token":"<received_jwt_token>"}}
GET
- /verify
curl -H 'Authorization: JWT <received_jwt_token>' -X GET http://127.0.0.1:3030/verify
# Server reply
{"ok":true,"user":{"_id":"5a0129ec1cc973ec2e92b985","email":"[email protected]","__v":0}}