https://github.com/james2doyle/serverjs-jwt-example
An example on how to use Server.js with JWT authentication
https://github.com/james2doyle/serverjs-jwt-example
authentication jwt nodejs serverjs
Last synced: about 2 months ago
JSON representation
An example on how to use Server.js with JWT authentication
- Host: GitHub
- URL: https://github.com/james2doyle/serverjs-jwt-example
- Owner: james2doyle
- License: mit
- Created: 2017-11-14T05:59:08.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-18T21:48:29.000Z (over 7 years ago)
- Last Synced: 2025-02-24T19:59:58.903Z (over 1 year ago)
- Topics: authentication, jwt, nodejs, serverjs
- Language: JavaScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Server.js JWT Example
=====================
> An example on how to use [Server.js](https://serverjs.io/) with JWT authentication.
## Quick Start
* `npm install`
* copy `example-config.js` to `config.js`
* update `config.js` with the correct details
* `npm start`
## Setup
#### Home Route
The default page is unauthenticated by default. And returns a simple login form that shows how the login works.
#### Authenticating a user
```
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: 'admin@admin.com',
first_name: 'Admin',
last_name: 'Account',
},
}
```
### Coding style
Airbnb has an excellent [style guide](https://github.com/airbnb/javascript) for ES6. We will follow the guide and adhere to the recommended coding style.
### ESLint
We will use ESLint with Airbnb style and pre-parse our code to detect violations of the style.
## Commands
### Run
```
npm start
```
## License
[MIT](LICENSE)