https://github.com/rvpanoz/jwtauth
JSON Web Token implementation with HapiJS in collaboration with MongoDB via mongoose.
https://github.com/rvpanoz/jwtauth
authentication hapijs jwt-authentication mongodb mongoose nodejs
Last synced: about 2 months ago
JSON representation
JSON Web Token implementation with HapiJS in collaboration with MongoDB via mongoose.
- Host: GitHub
- URL: https://github.com/rvpanoz/jwtauth
- Owner: rvpanoz
- Created: 2018-10-09T18:58:30.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-10T21:50:18.000Z (over 7 years ago)
- Last Synced: 2025-06-21T10:05:22.369Z (about 1 year ago)
- Topics: authentication, hapijs, jwt-authentication, mongodb, mongoose, nodejs
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jwtauth
JSON Web Token implementation with HapiJS in collaboration with MongoDB via mongoose.
## Usage
Clone the repository and then issue the command to install application dependencies
`npm install`
In the repository root folder run the command to start the server
`npm start`
## Create a new user
Register a new user to the system
**URL** : `/api/user/create`
**Method** : `POST`
**Auth required** : NO
**Payload example**
```json
{
"email": "foo@bar.com",
"password": "061182"
}
```
## Success Responses
**Condition** : Data provided is valid and User is created.
**Code** : `200 OK`
**Content example** : Response with the new user data
```json
{
"success": true,
"data": {
"user": {
"created_at": "2018-10-10T21:34:41.417Z",
"_id": "5bbe7077a613335cef0fd7ec",
"email": "foo@bar.com",
"password": "$2b$10$UmonZBB3bx8sxJU3SQpS.e60Gq.FMsyunTlJ6q58VsXEqXNGcEawi",
"__v": 0
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjViYmU3MDc3YTYxMzMzNWNlZjBmZDdlYyIsImVtYWlsIjoicnZwYW5vemhoNTUyOUBnbWFpbC5jb20iLCJpYXQiOjE1MzkyMDcyODcsImV4cCI6MTUzOTIxMDg4N30.Y-E__abwHOhJX5UQDpW4uETyRrRRJCbU7QeRha_mjTs"
}
}
```
## Error Response - Email taken
**Condition** : If provided email is taken
**Code** : `400 BAD REQUEST`
**Content example** :
```json
{
"statusCode": 400,
"error": "Bad Request",
"message": "Email taken"
}
```
## Authenticate user
Authenticate a user using email and password
**URL** : `/api/user/authenticate`
**Method** : `POST`
**Auth required** : NO
**Payload example**
```json
{
"email": "foo@bar.com",
"password": "061182"
}
```
## Success Responses
**Condition** : Data provided is valid and User is authenticated.
**Code** : `200 OK`
**Content example** : Response with the user's email and token
```json
{
"success": true,
"data": {
"user": "foo@bar.com",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ2cGFub3poaDU1MzI5QGdtYWlsLmNvbSIsImlhdCI6MTUzOTIwNzk3NiwiZXhwIjoxNTM5MjExNTc2fQ.keGuJZKWMwP4SNhvE_qyNHAIWx979vOFjB7obtrTHdk"
}
}
```
## Add custom routes
Add your own routes to the routes folder. In order to register the routes with the server import your routes in `./server.js` and then issue the command
```javascript
import { your_routes } from "./routes";
server.route(your_routes);
```
## Notes
- You can change the default configuration file `./config.js` to setup your mongodb installation.