feat(sprint-006): 버그 수정 3건 + JWT 인증 시스템
TASK-020 버그 수정:
- BUG-1: adminFetch Authorization 헤더 우선순위 수정 (JWT > API Key)
하네스 저장 실패 에러 핸들링 개선 (401/non-ok 명시적 처리)
- BUG-2: /admin/logs useEffect 초기 로드 추가 (마운트 시 자동 조회)
- BUG-3: costs/record python3 → node/python3/jq fallback 체인
TASK-021 JWT BE:
- User 모델 추가 (Prisma schema)
- AuthService: register(초대코드 검증+bcrypt) / login / refresh / getMe
- JwtStrategy (passport-jwt), JwtGuard, CompositeGuard (JWT+API Key)
- AuthController: /api/auth/{register,login,refresh,me}
- ThrottlerModule: 로그인 5회/분 Rate limiting
- CompositeGuard로 AdminController, CostsController Guard 전환
- EventsGateway: Socket.IO handshake JWT 검증 추가
- 테스트 26/26 pass
TASK-022 FE:
- AuthContext (AuthProvider + useAuth)
- AppShell (AuthProvider + AuthGate 라우트 보호)
- /login 페이지 (터미널 UI)
- /register 페이지 (초대 코드 필드)
- Sidebar: 로그인 사용자명 + 로그아웃 버튼
- FE 16 routes build 성공
This commit is contained in:
@@ -8,6 +8,8 @@ import {
|
||||
} from '@nestjs/websockets';
|
||||
import { Server, Socket } from 'socket.io';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@WebSocketGateway({
|
||||
cors: {
|
||||
@@ -26,12 +28,33 @@ export class EventsGateway
|
||||
|
||||
private readonly logger = new Logger(EventsGateway.name);
|
||||
|
||||
constructor(
|
||||
private readonly jwtService: JwtService,
|
||||
private readonly config: ConfigService,
|
||||
) {}
|
||||
|
||||
afterInit() {
|
||||
this.logger.log('WebSocket Gateway initialized');
|
||||
}
|
||||
|
||||
handleConnection(client: Socket) {
|
||||
this.logger.debug(`Client connected: ${client.id}`);
|
||||
// JWT 인증 확인 (token 파라미터 또는 Bearer 헤더)
|
||||
const token =
|
||||
(client.handshake.auth?.token as string) ??
|
||||
(client.handshake.headers.authorization as string)?.replace('Bearer ', '');
|
||||
|
||||
if (token) {
|
||||
try {
|
||||
const secret = this.config.get<string>('JWT_SECRET') ?? 'changeme';
|
||||
const payload = this.jwtService.verify(token, { secret });
|
||||
(client as any).user = payload;
|
||||
this.logger.debug(`WS client connected: ${client.id} (${payload.username})`);
|
||||
} catch {
|
||||
this.logger.debug(`WS client connected: ${client.id} (unauthenticated)`);
|
||||
}
|
||||
} else {
|
||||
this.logger.debug(`Client connected: ${client.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
handleDisconnect(client: Socket) {
|
||||
|
||||
Reference in New Issue
Block a user