Skip to content

Commit

Permalink
✨ feat: 토큰 유효기간 설정 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanggwangseong committed Dec 26, 2024
1 parent 0b66e45 commit 1c4dbf9
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ README.md

# docker
docker-compose-dev.yml

.clinic
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: auto deploy
on:
push:
branches:
- v1
- feature/56-v1-profile

jobs:
push_to_registry:
Expand Down Expand Up @@ -90,7 +90,8 @@ jobs:
echo "MYSQL_OUTBOUND_PORT=${{ secrets.MYSQL_OUTBOUND_PORT }}" >> .env
echo "MYSQL_INBOUND_PORT=${{ secrets.MYSQL_INBOUND_PORT }}" >> .env
echo "MYSQL_ROOT_PASSWORD=${{ secrets.MYSQL_ROOT_PASSWORD }}" >> .env
echo "JWT_ACCESS_TOKEN_EXPIRATION=${{ secrets.JWT_ACCESS_TOKEN_EXPIRATION }}" >> .env
echo "JWT_REFRESH_TOKEN_EXPIRATION=${{ secrets.JWT_REFRESH_TOKEN_EXPIRATION }}" >> .env
docker-compose down
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/backend:latest
docker pull ${{ secrets.NCP_CONTAINER_REGISTRY }}/backend-flame:latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ docker-compose.dev-bak.yml
grafana
prometheus

.clinic

clinic-report/**
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ mysql-data
grafana/**
prometheus/prometheus.yml
docker-compose.dev-bak.yml
clinic-report/**
.clinic
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
- DB_DATABASE=${DB_DATABASE}
- DB_SYNCHRONIZE=${DB_SYNCHRONIZE}
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- JWT_ACCESS_TOKEN_EXPIRATION=${JWT_ACCESS_TOKEN_EXPIRATION}
- JWT_REFRESH_TOKEN_EXPIRATION=${JWT_REFRESH_TOKEN_EXPIRATION}
- MAIL_HOST=${MAIL_HOST}
- MAIL_PORT=${MAIL_PORT}
- MAIL_USER=${MAIL_USER}
Expand All @@ -37,6 +39,8 @@ services:
- DB_DATABASE=${DB_DATABASE}
- DB_SYNCHRONIZE=${DB_SYNCHRONIZE}
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- JWT_ACCESS_TOKEN_EXPIRATION=${JWT_ACCESS_TOKEN_EXPIRATION}
- JWT_REFRESH_TOKEN_EXPIRATION=${JWT_REFRESH_TOKEN_EXPIRATION}
- MAIL_HOST=${MAIL_HOST}
- MAIL_PORT=${MAIL_PORT}
- MAIL_USER=${MAIL_USER}
Expand Down
2 changes: 1 addition & 1 deletion k6/scripts/articles-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const options = {
},
// 태그 추가
tags: {
testName: "v1-articles-result",
testName: "v1-articles-frame",
testType: "performance",
component: "articles",
version: "1.0",
Expand Down
4 changes: 4 additions & 0 deletions src/common/constants/env-keys.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export const ENV_API_BASE_URL = "API_BASE_URL" as const;

// jwt
export const ENV_JWT_SECRET_KEY = "JWT_SECRET_KEY" as const;
export const ENV_JWT_ACCESS_TOKEN_EXPIRATION =
"JWT_ACCESS_TOKEN_EXPIRATION" as const;
export const ENV_JWT_REFRESH_TOKEN_EXPIRATION =
"JWT_REFRESH_TOKEN_EXPIRATION" as const;

// server
export const ENV_SERVER_PORT = "SERVER_PORT" as const;
Expand Down
14 changes: 12 additions & 2 deletions src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { JwtService } from "@nestjs/jwt";
import * as bcrypt from "bcrypt";
import * as crypto from "crypto";

import { ENV_JWT_SECRET_KEY } from "@APP/common/constants/env-keys.const";
import {
ENV_JWT_ACCESS_TOKEN_EXPIRATION,
ENV_JWT_REFRESH_TOKEN_EXPIRATION,
ENV_JWT_SECRET_KEY,
} from "@APP/common/constants/env-keys.const";
import { BusinessErrorException } from "@APP/common/exception/business-error.exception";
import { MemberErrorCode } from "@APP/common/exception/error-code";
import { RegisterMemberDto } from "@APP/dtos/register-member.dto";
Expand Down Expand Up @@ -138,7 +142,13 @@ export class AuthService {
return this.jwtService.sign(payload, {
secret:
this.configService.get<string>(ENV_JWT_SECRET_KEY) || "secret",
expiresIn: isRefreshToken ? 3600 : 300,
expiresIn: isRefreshToken
? this.configService.get<string>(
ENV_JWT_REFRESH_TOKEN_EXPIRATION,
)
: this.configService.get<string>(
ENV_JWT_ACCESS_TOKEN_EXPIRATION,
),
});
}

Expand Down

0 comments on commit 1c4dbf9

Please sign in to comment.