Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aldy505/express-jwt-sample
Simple JWT auth implementation on Express
https://github.com/aldy505/express-jwt-sample
Last synced: 17 days ago
JSON representation
Simple JWT auth implementation on Express
- Host: GitHub
- URL: https://github.com/aldy505/express-jwt-sample
- Owner: aldy505
- License: mit
- Created: 2021-05-30T12:22:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-30T12:26:09.000Z (over 3 years ago)
- Last Synced: 2024-10-12T16:12:22.106Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Express JWT Sample
This is an easy one
## Setup
```bash
# have nodejs version 14 or above (because I use ES Module)
$ node -v
v14.17.0# install yarn if you haven't already
$ npm i -g yarn# check your yarn version
$ yarn -v
1.22.10# install required dependencies
$ yarn# run the server
$ yarn start
Express server is running on http://localhost:3000
```## Dependencies
```json
{
"dependencies": {
"argon2": "^0.27.2",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"lowdb": "^2.1.0",
"validator": "^13.6.0"
},
"devDependencies": {
"eslint": "^7.27.0",
"eslint-config-xo-space": "^0.27.0"
}
}
```## Routes
* `GET /` - Fetch all data you can use to login
```js
const users = await axios.get('http://localhost:3000/')
```
* `POST /login` - Login route
```js
const login = await axios.post(
'http://localhost:3000/login',
{
email: '[email protected]',
password: 'this is not a very secure password'
}
)
```
* `GET /verify` - Verify route
```js
const jwtToken = login.data.token
const verify = await axios.get(
'http://localhost:3000/verify',
{
headers: {
Authorization: `Bearer ${jwtToken}`
}
}
)
```
* `GET /data` - Data route
```js
const jwtToken = login.data.token
const data = await axios.get(
'http://localhost:3000/data',
{
headers: {
Authorization: `Bearer ${jwtToken}`
}
}
)
```## License
MIT © Reinaldy Rafli