Skip to content

Commit

Permalink
[feat] 메시지 보낼 때 resolve 후 validation 진행
Browse files Browse the repository at this point in the history
  • Loading branch information
khee2 committed Jun 12, 2024
1 parent d116d46 commit 5087be9
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ public void message(@RequestHeader(name = "ACCESS_TOKEN", required = false) Stri
MessageDto messageDto) {
try {
// Access Token 검증
if (accessToken == null || !jwtTokenProvider.validateToken(accessToken)) { // 메시지 전송 전 유효한 토큰인지 검증
throw new AccessDeniedException("Invalid or expired token");
if (accessToken != null && accessToken.startsWith("Bearer ")) {
String token = accessToken.substring(7);
if (jwtTokenProvider.validateToken(token)) {
// 메시지 전송 로직 호출
messageRoomService.handleMessage(messageDto.getRoomId(), messageDto.getSender(), messageDto);
} else {
throw new AccessDeniedException("Invalid or expired token");
}
} else {
throw new AccessDeniedException("Missing or invalid ACCESS_TOKEN header");
}
// 메시지 전송 로직 호출
messageRoomService.handleMessage(messageDto.getRoomId(), messageDto.getSender(), messageDto);
} catch (Exception e) {
log.error("Failed to send message: {}", e.getMessage());
throw e;
Expand Down

0 comments on commit 5087be9

Please sign in to comment.