Skip to content

Commit

Permalink
Merge branch 'feat/#39/jwt-verification' of https://github.com/modern…
Browse files Browse the repository at this point in the history
…-agile-team/8term-main-back into feat/#55/admin-login-api-feat
  • Loading branch information
gwgw123 committed Jan 2, 2025
2 parents c9d44a7 + 8b18d72 commit 57bedf5
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 175 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI/CD Docker
# 트리거를 수행할 브랜치를 지정합니다.
on:
push:
branches: [main, develop]
branches: [main, develop, feat/#39/jwt-verification]

# 환경설정
env:
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class AuthController {
}

// refreshToken을 검증하고 accessToken을 재발급
@Get('verify-refreshToken')
@Get('new-accessToken')
@HttpCode(201)
@UseGuards(AuthGuard('refreshToken'))
async verifyRefresh(@User() user: any, @Res() res: Response): Promise<any> {
Expand Down
97 changes: 0 additions & 97 deletions src/auth/guard/jwt.guard.ts

This file was deleted.

63 changes: 0 additions & 63 deletions src/auth/guard/logout.guard.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/auth/jwt/jwt.startegy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class AccessTokenStrategy extends PassportStrategy(
},
]),
// 시크릿키로 검증

secretOrKey: configService.get<string>('ACCESS_SECRET'),
// validate 메서드로 request 객체 전달
passReqToCallback: true,
Expand All @@ -34,7 +35,7 @@ export class AccessTokenStrategy extends PassportStrategy(
});
}

async validate(payload: any): Promise<any> {
async validate(request: Request, payload: any): Promise<any> {
const user = await this.userService.getUser(payload.userId);
return user;
}
Expand Down Expand Up @@ -68,7 +69,7 @@ export class RefreshTokenStrategy extends PassportStrategy(
});
}

async validate(payload: any, request: Request): Promise<any> {
async validate(request: Request, payload: any): Promise<any> {
const refreshToken = request?.cookies?.refreshToken;
if (!refreshToken) {
throw new UnauthorizedException('No Refresh Token provided');
Expand Down
4 changes: 2 additions & 2 deletions src/auth/redis/redis.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import * as redisStore from 'cache-manager-redis-store';
useFactory: async (configService: ConfigService) => ({
store: redisStore,
host: configService.get<string>('REDIS_HOST'),
port: configService.get<number>('REDIS_PORT'),
port: Number(configService.get<string>('REDIS_PORT')),
password: configService.get<string>('REDIS_PASSWORD'),
ttl: Number(configService.get<number>('REDIS_EXPIRATION_TIME')),
ttl: Number(configService.get<string>('REDIS_EXPIRATION_TIME')),
}),
inject: [ConfigService],
}),
Expand Down
4 changes: 2 additions & 2 deletions src/auth/services/cookie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class CookieService {
domain: this.configService.get<string>('COOKIE_DOMAIN'),
sameSite: 'none' as 'none', // none 타입으로 지정해줘야 함.
maxAge: Number(
this.configService.get<number>('ACCESS_COOKIE_EXPIRATION_TIME'),
this.configService.get<string>('ACCESS_COOKIE_EXPIRATION_TIME'),
),
path: '/',
};
Expand All @@ -31,7 +31,7 @@ export class CookieService {
domain: this.configService.get<string>('COOKIE_DOMAIN'),
sameSite: 'none' as 'none',
maxAge: Number(
this.configService.get<number>('REFRESH_COOKIE_EXPIRATION_TIME'),
this.configService.get<string>('REFRESH_COOKIE_EXPIRATION_TIME'),
),
path: '/', // refreshToken은 특정 경로로 제한 가능
};
Expand Down
4 changes: 2 additions & 2 deletions src/auth/services/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class TokenService {
const accessToken = this.jwtService.sign(payload, {
secret: this.configService.get<string>('ACCESS_SECRET'),
expiresIn: Number(
this.configService.get<number>('ACCESS_EXPIRATION_TIME'),
this.configService.get<string>('ACCESS_EXPIRATION_TIME'),
),
});
return accessToken;
Expand All @@ -35,7 +35,7 @@ export class TokenService {
const refreshToken = this.jwtService.sign(payload, {
secret: this.configService.get<string>('REFRESH_SECRET'),
expiresIn: Number(
this.configService.get<number>('REFRESH_EXPIRATION_TIME'),
this.configService.get<string>('REFRESH_EXPIRATION_TIME'),
),
});
this.redisService.set(String(userId), refreshToken);
Expand Down
10 changes: 9 additions & 1 deletion src/parts/parts.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export class PartsRepository {
});
}

async findAllPartBySectionId(sectionId: number): Promise<Part[]> {
return this.prisma.part.findMany({
where: { sectionId },
orderBy: { order: 'asc' },
});
}

async findOnePartById(id: number): Promise<Part> {
return this.prisma.part.findUnique({
where: { id },
Expand All @@ -31,8 +38,9 @@ export class PartsRepository {
});
}

async findPartMaxOrder(): Promise<number> {
async findPartMaxOrderBySectionId(sectionId: number): Promise<number> {
const result = await this.prisma.part.aggregate({
where: { sectionId },
_max: { order: true },
});
return result._max.order ?? 0;
Expand Down
11 changes: 7 additions & 4 deletions src/parts/parts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export class PartsService {
* @returns 재배열된 파트 ID 배열
*/
private async reorderPartIds(
movingId: number,
{ id, sectionId }: Part,
newOrder: number,
): Promise<number[]> {
const parts = await this.partsRepository.findAllPart();
const movingId = id;

const parts = await this.partsRepository.findAllPartBySectionId(sectionId);
const partIds = parts.map((part) => part.id);
const currentIndex = partIds.indexOf(movingId);

Expand Down Expand Up @@ -90,7 +92,8 @@ export class PartsService {
throw new ConflictException('part의 이름은 유니크 해야합니다.');
}

const maxOrder = await this.partsRepository.findPartMaxOrder();
const maxOrder =
await this.partsRepository.findPartMaxOrderBySectionId(sectionId);
const newOrder = maxOrder + 1;

return this.partsRepository.createPartById({ ...body, order: newOrder });
Expand All @@ -110,7 +113,7 @@ export class PartsService {
}

// 섹션 순서 재배치를 위한 처리
const updatedSectionIds = await this.reorderPartIds(id, body.order);
const updatedSectionIds = await this.reorderPartIds(part, body.order);

// 데이터베이스의 섹션 순서를 업데이트
await this.updatePartOrders(updatedSectionIds);
Expand Down

0 comments on commit 57bedf5

Please sign in to comment.