Skip to content

Commit 259f6e0

Browse files
committed
[Refactor] OAuth ID 타입 Long → String으로 변경
1 parent ae487de commit 259f6e0

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/main/java/com/moa/moa_server/domain/auth/entity/OAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class OAuth {
1818

1919
@Id
2020
@Column(length = 100, nullable = false)
21-
private Long id; // 소셜 사용자 ID
21+
private String id; // 소셜 사용자 ID
2222

2323
@ManyToOne(fetch = FetchType.LAZY)
2424
@JoinColumn(name = "user_id", nullable = false)

src/main/java/com/moa/moa_server/domain/auth/handler/AuthErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public enum AuthErrorCode implements BaseErrorCode {
1414
KAKAO_TOKEN_FAILED(HttpStatus.UNAUTHORIZED),
1515
KAKAO_USERINFO_FAILED(HttpStatus.UNAUTHORIZED),
1616
OAUTH_NOT_FOUND(HttpStatus.NOT_FOUND),
17-
INVALID_REDIRECT_URI(HttpStatus.BAD_REQUEST),;
17+
INVALID_REDIRECT_URI(HttpStatus.BAD_REQUEST),
18+
INVALID_KAKAO_ID(HttpStatus.INTERNAL_SERVER_ERROR),;
1819

1920
private final HttpStatus status;
2021

src/main/java/com/moa/moa_server/domain/auth/repository/OAuthRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public interface OAuthRepository extends JpaRepository<OAuth, Long> {
1111

12-
Optional<OAuth> findById(@NonNull Long id);
12+
Optional<OAuth> findById(@NonNull String id);
1313
void deleteByUserId(Long userId);
1414
Optional<OAuth> findByUser(User user);
1515
}

src/main/java/com/moa/moa_server/domain/auth/service/strategy/KakaoOAuthLoginStrategy.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public LoginResult login(String code, String redirectUri) {
6565
String kakaoAccessToken = getAccessToken(code, redirectUri);
6666

6767
// 카카오 액세스 토큰으로 사용자 정보 요청
68-
Long kakaoId = getUserInfo(kakaoAccessToken);
68+
String kakaoId = getUserInfo(kakaoAccessToken);
6969

7070
// 사용자 정보 DB 조회
7171
Optional<OAuth> oAuthOptional = oAuthRepository.findById(kakaoId);
@@ -116,7 +116,7 @@ private String getAccessToken(String code, String redirectUri) {
116116
}
117117
}
118118

119-
private Long getUserInfo(String accessToken) {
119+
private String getUserInfo(String accessToken) {
120120

121121
HttpHeaders headers = new HttpHeaders();
122122
headers.setBearerAuth(accessToken);
@@ -126,7 +126,8 @@ private Long getUserInfo(String accessToken) {
126126

127127
try {
128128
ResponseEntity<Map> response = restTemplate.postForEntity(kakaoUserInfoUri, request, Map.class);
129-
return (Long) response.getBody().get("id");
129+
Object kakaoId = response.getBody().get("id");
130+
return String.valueOf(kakaoId);
130131
} catch (Exception e) {
131132
throw new AuthException(AuthErrorCode.KAKAO_USERINFO_FAILED);
132133
}

src/main/java/com/moa/moa_server/domain/user/service/UserService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,16 @@ public void deleteUser(Long userId) {
158158
voteRepository.softDeleteAllByUser(user);
159159

160160
// 4. 카카오 연동 해제
161-
Long kakaoUserId = oauthRepository.findByUser(user)
161+
String kakaoUserId = oauthRepository.findByUser(user)
162162
.filter(oauth -> oauth.getProviderCode() == OAuth.ProviderCode.KAKAO)
163163
.map(OAuth::getId)
164164
.orElseThrow(() -> new AuthException(AuthErrorCode.OAUTH_NOT_FOUND));
165-
authService.unlinkKakaoAccount(kakaoUserId);
165+
try {
166+
Long kakaoUserIdLong = Long.parseLong(kakaoUserId);
167+
authService.unlinkKakaoAccount(kakaoUserIdLong);
168+
} catch (NumberFormatException e) {
169+
throw new AuthException(AuthErrorCode.INVALID_KAKAO_ID);
170+
}
166171

167172
// 5. 토큰, OAuth 삭제 (hard delete)
168173
tokenRepository.deleteByUserId(userId);

0 commit comments

Comments
 (0)