- User can sign up
- User can sign in
POST /api/auth/register
: Creates a new userPOST /api/auth/login
: Logs in a user
Signup expects
{
firstname: string,
lastname: string,
email: string,
password: string
}
Signin expects
{
email: string,
password: string
}
- NodeJS/Express: Server
- MySQL: Storage
- JWT: Token based authentication
- bcryptjs: Password security
- winston/morgan: Logs
- Joi: Validations
start
: Starts the server with nodestart:dev
: Starts the server in watch modedb:up
: Creates the databasedb:down
: Drops the databasetables:up
: Creates database tablesdb:init
: Creates both the database and tables
You can either fork this repository or clone it by starting your terminal, then change the directory to where you would like to save it and run
git clone https://github.com/desirekaleba/node-mysql-jwt-auth.git
Change to the newly downloaded directory with
cd node-mysql-jwt-auth
Rename the file named .env.example
to .env
and update the variable values with valid ones
Install the required dependencies with
npm install
Initialize the database with
npm run db:init
Start the app with
npm start
You can also start it in watch mode with
npm run start:dev
.
├── README.md
├── package-lock.json
├── package.json
└── src
├── app.js
├── config
│ ├── db.config.init.js
│ └── db.config.js
├── controllers
│ └── auth.controller.js
├── database
│ ├── queries.js
│ └── scripts
│ ├── dbDown.js
│ ├── dbUp.js
│ └── tablesUp.js
├── index.js
├── middlewares
│ ├── asyncHandler.js
│ ├── checkEmail.js
│ └── validatorHandler.js
├── models
│ └── user.model.js
├── routes
│ └── auth.route.js
├── utils
│ ├── logger.js
│ ├── password.js
│ ├── secrets.js
│ └── token.js
└── validators
└── auth.js