If you don't familiar with RefreshToken, and you don't know why we should use it, the below links can be helpful:
- https://developer.okta.com/docs/guides/refresh-tokens/main/
- https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/
- https://auth0.com/learn/refresh-tokens/
- Make and configure .env file in the root folder of the project:
# .env
PORT = SERVICE_PORT
DATABASE_URL = YOUR_POSTGRE_DATABASE_URI_CONNECTION
# SecretKey must have at least 32 characters and contains uppercase characters, lowercase characters, and digits.
JWT_ACCESS_TOKEN_SECRET_KEY = YOUR_SECRET_KEY
JWT_REFRESH_TOKEN_SECRET_KEY = YOUR_SECRET_KEY
# Tokens LifeTime
ACCESS_TOKEN_LIFE_TIME = 15 #Minutes
REFRESH_TOKEN_LIFE_TIME = 7 #Days
# Rate Limiting
RATE_LIMIT_TIME_TO_LIVE = 10 #Seconds
RATE_LIMIT_MAX_NUMBER_REQUEST = 2
# CORS
CORS_ORIGIN = http://test.com
# Zone
TIME_ZONE = Asia/Tehran
- Generate Prisma Client:
npx prisma generate
- Push the Prisma schema state to the database:
npx prisma db push
- Run the application:
npm run start
Route | Method | Description |
---|---|---|
/api/v1/auth/signup | Post | Signup |
/api/v1/auth/signin | Post | Signin |
/api/v1/auth/refresh | Post | Refresh |
/api/v1/auth/logout | Post | Logout |
Parameter | Description | MinLength | MaxLength |
---|---|---|---|
username | username can only contain lowercase characters, digits, and underscores | 5 | 10 |
password | password must contain at least one uppercase character, a lowercase character, a digit, and a special character | 8 | 15 |
Parameter | MinLength | MaxLength |
---|---|---|
username | 4 | 20 |
password | 4 | 20 |
Parameter | Value Format |
---|---|
Authorization | Bearer [RefreshToken] |
Parameter | Value Format |
---|---|
Authorization | Bearer [AccessToken] |
You can find it (*.postman_collection.json) in the root folder of the project.