https://github.com/hasinthak/nodejs-jwt-api
NodeJs API for JWT authentication and Authorization. No Static assets are served. Only the API s are exposed via the URL.
https://github.com/hasinthak/nodejs-jwt-api
jwt nodejs redis
Last synced: about 2 months ago
JSON representation
NodeJs API for JWT authentication and Authorization. No Static assets are served. Only the API s are exposed via the URL.
- Host: GitHub
- URL: https://github.com/hasinthak/nodejs-jwt-api
- Owner: hasinthaK
- Created: 2019-12-31T11:31:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-12-09T03:13:39.000Z (over 5 years ago)
- Last Synced: 2025-04-03T05:27:04.093Z (about 1 year ago)
- Topics: jwt, nodejs, redis
- Language: JavaScript
- Homepage: https://nodejwtapi.herokuapp.com
- Size: 90.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeJs JWT Authentication API
### Environment vars to be updated
Update these env variables in `.env` file or platform specific environment
* - required env vars(if not set, will fallback to predefined defaults)
```
DB_CONN - remote db connection uri
JWT_SECRET* - secret for jwt
JWT_REFRESH_SECRET* - secret for refresh token
JWT_EXP - expiration time for jwt(s)
JWT_SECRET_EXP - expiration time for refresh token(s)
REDIS_HOST - redis db host uri
REDIS_PORT - redis db port
REDIS_PASS - redis db password
REDIS_EXP - Expiration for a Redis key
PORT - server port/default 3000
```
Redis & MongoDB should be installed either locally if remote connections are not provided & running in default configs.
```
Fallback defaults
MongoDB => db name - 'local', port - 27017
Redis => host - localhost, port - 6379
```
---
## Available endpoints
- ### Register - Validates & create new user
```json
POST
/user/register
{
"name":"",
"email":"",
"password":""
}
response body - { user_id: created user's ID in DB }
```
- ### Login - returns a JWT
```json
POST
/user/login
{
"email":"",
"password":""
}
response body - { token: JWT, refreshtoken: refresh JWT }
```
- ### Private routes - Can be accessed only via presenting valid token inside 'auth-token' custom header
```
test private Route:
/get
request header: 'auth-token: a valid JWT'
```