server.js-auth-example

PassportJS + JWT + ServerJS

MIT License

Stars
6
Committers
1

server.js-auth-example

PassportJS + JWT + ServerJs

Setup

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

Usage

Register new user

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."}

Login

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>"}}

Verify

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}}

License

MIT