From 5f062fecbaf642d69ca25c4f4419a164ce0b2273 Mon Sep 17 00:00:00 2001 From: younggyo Date: Thu, 1 Feb 2024 16:51:56 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20update=20userId=20=EC=B6=94=EC=B6=9C?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/reddiserver/auth/service/OAuthService.java | 8 ++++++-- .../example/reddiserver/controller/ChatGptController.java | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/reddiserver/auth/service/OAuthService.java b/src/main/java/com/example/reddiserver/auth/service/OAuthService.java index 15eaff0..fc8c590 100644 --- a/src/main/java/com/example/reddiserver/auth/service/OAuthService.java +++ b/src/main/java/com/example/reddiserver/auth/service/OAuthService.java @@ -80,9 +80,13 @@ public LoginResponseDto login(String code, String redirectUri) { public Long getUserId() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication != null) { - CustomAuthenticationDetails customDetails = (CustomAuthenticationDetails) authentication.getDetails(); - return customDetails.getUserId(); + Object details = authentication.getDetails(); + if (details instanceof CustomAuthenticationDetails) { + CustomAuthenticationDetails customDetails = (CustomAuthenticationDetails) details; + return customDetails.getUserId(); + } } return null; // 인증 정보가 없거나 CustomAuthenticationDetails를 사용하지 않는 경우 diff --git a/src/main/java/com/example/reddiserver/controller/ChatGptController.java b/src/main/java/com/example/reddiserver/controller/ChatGptController.java index e736fb1..9a3a835 100644 --- a/src/main/java/com/example/reddiserver/controller/ChatGptController.java +++ b/src/main/java/com/example/reddiserver/controller/ChatGptController.java @@ -23,7 +23,6 @@ public class ChatGptController { private final ChatGptService chatGptService; private final OAuthService oAuthService; - @SecurityRequirement(name = "Authorization") @Operation(summary = "ChatGPT로 원하는 브랜드 만들기") @PostMapping("/question") public ApiResponse postChat(@RequestBody ChatGptRequest chatGptRequest) throws JsonProcessingException {