diff --git a/server/.gitignore b/server/.gitignore index cd957075..9c2e25b7 100644 --- a/server/.gitignore +++ b/server/.gitignore @@ -16,7 +16,7 @@ build/ bin/ !**/src/main/**/bin/ !**/src/test/**/bin/ - +.eslintcache ### IntelliJ IDEA ### diff --git a/server/src/main/java/com/example/config/DiaryConfig.java b/server/src/main/java/com/example/config/DiaryConfig.java index 28edb76a..63ceac3f 100644 --- a/server/src/main/java/com/example/config/DiaryConfig.java +++ b/server/src/main/java/com/example/config/DiaryConfig.java @@ -19,6 +19,7 @@ public CorsFilter corsFilter() { CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost:8080")); // 개발 중일 때 + config.setAllowedOrigins(List.of("http://localhost:3000", "http://localhost:3000/authuser")); // config.setAllowedOrigins(List.of("https://my-react-app.com")); // 배포 후 config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")); config.setAllowedHeaders(List.of("*")); diff --git a/server/src/main/java/com/example/controller/DiaryController.java b/server/src/main/java/com/example/controller/DiaryController.java index a5d6b5b5..afc8edec 100644 --- a/server/src/main/java/com/example/controller/DiaryController.java +++ b/server/src/main/java/com/example/controller/DiaryController.java @@ -8,6 +8,10 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + @RestController @RequestMapping("/post") public class DiaryController { @@ -21,30 +25,34 @@ public DiaryController(Diaryservice diaryService, JwtAuthenticationFilter jwtAut } @PostMapping("/write_diary") - public ResponseEntity writeDiary(@RequestBody DiaryDto diaryDto, @RequestHeader("Authorization") String authorizationHeader) { + public ResponseEntity> writeDiary(@RequestBody DiaryDto diaryDto, @RequestHeader("Authorization") String authorizationHeader) { // JWT 토큰을 요청 헤더에서 추출 String jwt = extractJwtFromHeader(authorizationHeader); if (jwt == null) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("JWT 토큰이 없습니다"); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(Collections.singletonMap("message", "JWT 토큰이 없습니다")); } // 토큰 검증 및 사용자 정보 추출 if (!jwtAuthenticationFilter.validateToken(jwt)) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("유효하지 않은 JWT 토큰입니다"); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(Collections.singletonMap("message", "유효하지 않은 JWT 토큰입니다")); } String loginId = jwtAuthenticationFilter.getUserIdFromJwt(jwt); if (loginId == null) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("유효하지 않은 JWT 토큰입니다"); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(Collections.singletonMap("message", "유효하지 않은 JWT 토큰입니다")); } // 다이어리 DTO에 로그인 ID 설정 diaryDto.setLogin_id(loginId); diaryService.writeDiary(diaryDto); - return ResponseEntity.status(HttpStatus.CREATED).body("저장이 완료되었습니다"); + // 성공 응답 생성 + Map response = new HashMap<>(); + response.put("message", "저장이 완료되었습니다"); + + return ResponseEntity.status(HttpStatus.CREATED).body(response); } // 요청 헤더에서 JWT 토큰을 추출하는 메서드 diff --git a/server/src/main/java/com/example/controller/SecurityLoginController.java b/server/src/main/java/com/example/controller/SecurityLoginController.java index 7791dae3..3533894b 100644 --- a/server/src/main/java/com/example/controller/SecurityLoginController.java +++ b/server/src/main/java/com/example/controller/SecurityLoginController.java @@ -1,4 +1,4 @@ -package com.example.controller; +/*package com.example.controller; import com.example.dto.LoginRequest; import com.example.domain.entity.Member; @@ -64,4 +64,4 @@ public ResponseEntity oauthLoginSuccess() { return ResponseEntity.ok(message); // 성공 메시지를 반환함 } -} +}*/