An example on how to use Server.js with JWT authentication.
npm install
- copy
example-config.js
toconfig.js
- update
config.js
with the correct details npm start
The default page is unauthenticated by default. And returns a simple login form that shows how the login works.
POST http://localhost:3000/login
{
"username": "john.doe",
"password": "foobar"
}
This will return the token as an object:
{
"token": "some.crazy.string"
}
You can then access protected routes behind the authentication middleware:
GET http://localhost:3000/protected
{
message: 'hello! thanks for the token',
user: {
id: 123,
email: '[email protected]',
first_name: 'Admin',
last_name: 'Account',
},
}
Airbnb has an excellent style guide for ES6. We will follow the guide and adhere to the recommended coding style.
We will use ESLint with Airbnb style and pre-parse our code to detect violations of the style.
npm start