This is a Boilerplate to start quick and fresh your new project with authentication and authorization using JWT, TypeORM and TypeScript. This project was made by Matheus Silva - Youtube.
-
- Register User with: Name, Email and Password.
- On Register: check if user alreay exists (unique email).
- On Register: check if user added name, email and password.
- Hash user password using bcryptjs.
-
- Authenticate user with Email and Password.
- On authenticate: check if user added name and password.
- On authenticate: check if user is valid.
- On authenticate: check if password matches with hash.
- Receive token as response containing: id, name, email, user type (admin / user).
-
- Middleware check if has a token and if is valid.
The project is made with:
-
- Is required to install Node.js
- In order to run scripts and install dependencies you need to install a package manager (ie: YARN).
- First step, clone this github repository:
$ git clone https://github.com/dpisati/node-typeorm.git
- Add variables on
.env
file:
The api requires some environment variables stored inside the .env
file.
Example:
File: .env
Content:
PORT = add a port or run on 3333 by default
JWT_SECRET = strong password to be used by JWT
JWT_EXPIRES_IN = set how long the token should be valid
- Configure
ormconfig.json
to connect the database. Default values as below:
{
"type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "",
"database": "node-typeorm",
"entities": [
"src/app/models/*.ts"
],
"migrations": [
"src/database/migrations/*.ts"
],
"cli": {
"migrationsDir": "src/database/migrations"
}
}
- Run the application:
# Install dependencies.
$ yarn install
## Create the database using TypeORM
$ yarn typeorm migration:run
# Start the API
$ yarn run dev
- Create a Fork from this repo,
- Create a branch with your feature:
git checkout -b my-feature
- Commit changes:
git commit -m 'feat: My new feature'
- Push to your branch:
git push origin my-feature