Skip to content

frenchbread/server.js-auth-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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":"some@mail.com","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":"some@mail.com","password":"somepassword"}' http://localhost:3030/login

# Server reply
{"ok":true,"data":{"user":{"_id":"5a0129ec1cc973ec2e92b985","email":"some@mail.com"},"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":"some@mail.com","__v":0}}

License

MIT

About

PassportJS + JWT + ServerJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages