Conversation
Summary of ChangesHello @lingard1234, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! 이 풀 리퀘스트는 애플리케이션에 카카오 OAuth2 소셜 로그인 기능을 도입합니다. 사용자가 카카오 계정을 통해 간편하게 로그인하고 JWT 기반의 인증 토큰을 발급받아 서비스에 접근할 수 있도록 하여 사용자 경험을 향상시키고 인증 시스템을 확장하는 것이 주된 목적입니다. Spring Security의 OAuth2 기능을 활용하여 안전하고 효율적인 인증 흐름을 구축했습니다. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
카카오 OAuth2 로그인을 구현하신 것을 확인했습니다. Spring Security와 JWT를 활용한 전반적인 흐름은 잘 구성되어 있습니다. 다만, 몇 가지 개선점을 제안합니다. JWT 라이브러리 버전을 최신으로 업데이트하고, 하드코딩된 URL들을 외부 설정으로 분리하는 것이 좋습니다. 또한, JWT 필터의 경로 문제와 사용자 프로필 업데이트 로직의 버그를 수정하고, 데이터베이스 스키마의 확장성을 고려한 변경을 제안합니다. 불필요해 보이는 테스트 파일도 정리하는 것이 좋겠습니다. 자세한 내용은 각 파일에 남긴 코멘트를 참고해주세요.
| "/oauth2/", | ||
| "/login/oauth2/", | ||
| "/oauth/callback", | ||
| "/api/v1/test", |
| implementation 'io.jsonwebtoken:jjwt-api:0.12.3' | ||
| runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3' | ||
| runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.3' |
There was a problem hiding this comment.
| .successHandler(oAuth2SuccessHandler) | ||
| .failureHandler((request, response, exception) -> { | ||
| log.error("OAuth2 login failed", exception); | ||
| response.sendRedirect("/api/test?error=" + exception.getMessage()); |
| configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")); | ||
| configuration.setAllowedHeaders(List.of("*")); | ||
| configuration.setAllowCredentials(true); // 쿠키/인증정보 포함 요청 | ||
| configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:8080")); |
| String redirectUrl = String.format("http://localhost:8080/api/login/success?accessToken=%s&refreshToken=%s", | ||
| URLEncoder.encode(accessToken, StandardCharsets.UTF_8), | ||
| URLEncoder.encode(refreshToken, StandardCharsets.UTF_8) | ||
| ); |
| if (email != null && !email.equals(user.getEmail())) { | ||
| user.updateProfile(email, name); | ||
| userRepository.save(user); | ||
| } |
There was a problem hiding this comment.
현재 로직은 사용자의 이메일이 기존과 다를 경우에만 프로필 정보(이메일, 이름)를 업데이트합니다. 만약 사용자가 카카오에서 닉네임만 변경했다면, 우리 서비스의 사용자 이름이 업데이트되지 않는 문제가 발생합니다. 이름이나 이메일 중 하나라도 변경되었다면 프로필을 업데이트하도록 조건을 수정하는 것이 좋습니다.
| if (email != null && !email.equals(user.getEmail())) { | |
| user.updateProfile(email, name); | |
| userRepository.save(user); | |
| } | |
| if ((email != null && !email.equals(user.getEmail())) || (name != null && !name.equals(user.getName()))) { | |
| user.updateProfile(email, name); | |
| userRepository.save(user); | |
| } |
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, unique = true) |
There was a problem hiding this comment.
providerId 필드에 unique = true 제약조건이 설정되어 있습니다. 현재는 카카오 로그인만 지원하지만, 추후 다른 OAuth2 프로바이더(예: Google, Naver)를 추가할 경우 다른 프로바이더의 사용자와 providerId가 겹칠 수 있습니다. 이를 방지하기 위해, 이 필드의 unique = true를 제거하고, User 엔티티 클래스 상단에 @Table(uniqueConstraints = @UniqueConstraint(columnNames = {"providerId", "provider"})) 어노테이션을 추가하여 providerId와 provider의 조합이 유니크하도록 복합 유니크 키를 설정하는 것을 강력히 권장합니다.
| @Column(nullable = false, unique = true) | |
| @Column(nullable = false) |
There was a problem hiding this comment.
provider id unique 추가해주세요
| package com.example.RealMatch.test; | ||
|
|
||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| public class TestController { | ||
|
|
||
| @GetMapping("/success") | ||
| public String success() { | ||
| return "KAKAO LOGIN SUCCESS"; | ||
| } | ||
| } |
There was a problem hiding this comment.
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(nullable = false, unique = true) |
There was a problem hiding this comment.
provider id unique 추가해주세요
| @Column(nullable = false) | ||
| private String provider; // kakao | ||
|
|
||
| private String email; |
There was a problem hiding this comment.
이메일도 nullable로 해주세요
개요
OAuth2, JWT 기반 카카오 소셜 로그인 기능 구현
카카오 로그인 → redirect → Access Token
목표
구현 내용
동작 흐름
테스트 방법