Skip to content

Commit c5c85aa

Browse files
authored
Merge pull request #217 from Central-MakeUs/release
Release
2 parents 575a571 + 1cd4411 commit c5c85aa

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

โ€Žsrc/main/java/com/example/ForDay/domain/auth/service/AuthService.javaโ€Ž

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,34 +226,53 @@ public TokenValidateResDto tokenValidate() {
226226
@Transactional
227227
public SwitchAccountResDto switchAccount(@Valid SwitchAccountReqDto reqDto, CustomUserDetails user) {
228228
User currentUser = userUtil.getCurrentUser(user); // ํ˜„์žฌ ์œ ์ €
229+
230+
log.info("Switch account attempt - userId: {}, currentRole: {}, requestSocialType: {}",
231+
currentUser.getId(),
232+
currentUser.getRole(),
233+
reqDto.getSocialType());
234+
229235
if(!currentUser.getRole().equals(Role.GUEST)) { // ๊ฒŒ์ŠคํŠธ๊ฐ€ ์•„๋‹ˆ๋ฉด ์˜ˆ์™ธ
236+
log.warn("Switch account denied - userId: {} is not GUEST (role: {})",
237+
currentUser.getId(),
238+
currentUser.getRole());
230239
throw new CustomException(ErrorCode.NO_GUEST_ACCESS);
231240
}
232241

233242
if(reqDto.getSocialType() == SocialType.GUEST) { // ์š”์ฒญ ํƒ€์ž…์ด ๊ฒŒ์ŠคํŠธ์ด๋ฉด ์˜ˆ์™ธ
243+
log.warn("Invalid switch request - userId: {} tried to switch to GUEST",
244+
currentUser.getId());
234245
throw new CustomException(ErrorCode.INVALID_REQUEST_TYPE);
235246
}
236247

237248
String accessToken = "";
238249
String refreshToken = "";
239250
switch (reqDto.getSocialType()) {
240251
case KAKAO -> {
252+
log.info("Calling Kakao API - userId: {}", currentUser.getId());
253+
241254
// kakao ํšŒ์› ์ •๋ณด ๋ฐ›์•„์˜ค๊ธฐ
242255
KakaoProfileDto kakaoProfileDto = kakaoService.getKakaoProfile(reqDto.getSocialCode());
243256

244257
String socialId = SocialType.KAKAO.toString().toLowerCase() + "_" + kakaoProfileDto.getId();
245258

246259
// ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํšŒ์›์ด๋ฉด ์ „ํ™˜ ๋ฐฉ์ง€
247260
if(userRepository.existsBySocialId(socialId)) {
261+
log.warn("Switch failed - socialId already exists: {}", socialId);
248262
throw new CustomException(ErrorCode.SOCIAL_ALREADY_EXISTS);
249263
}
250264

251265
// ์ƒˆ๋กญ๊ฒŒ ์ „ํ™˜ํ•˜๋Š” ์œ ์ €์ด๋ฉด ๊ธฐ์กด Role: GUEST -> USER, GUEST -> KAKAO
252266
currentUser.switchAccount(kakaoProfileDto.getKakao_account().getEmail(), Role.USER, SocialType.KAKAO, socialId);
267+
userRepository.save(currentUser);
253268
accessToken = jwtUtil.createAccessToken(socialId, Role.USER, SocialType.KAKAO);
254269
refreshToken = jwtUtil.createRefreshToken(socialId);
270+
271+
log.info("Switch success - userId: {}, newSocialType: KAKAO, socialId: {}",
272+
currentUser.getId(), socialId);
255273
}
256274
case APPLE -> {
275+
log.info("Calling Apple API - userId: {}", currentUser.getId());
257276
// ํ”„๋ก ํŠธ์—์„œ code๊ฐ’์„ ๋ณด๋‚ด๋ฉด์„œ ๋กœ๊ทธ์ธ/ํšŒ์›๊ฐ€์ž… ์š”์ฒญ์„ ํ•œ๋‹ค.
258277
// code์™€ ์• ํ”Œ ์„ค์ •๊ฐ’์„ ์ด์šฉํ•˜์—ฌ ์ง์ ‘ JWT ํ† ํฐ ์ƒ์„ฑํ›„ apple api์— ์œ ์ € ์ •๋ณด ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค. -> ์‘๋‹ต์œผ๋กœ idToken๊ณผ accessToken์„ ๋ฐ›๋Š”๋‹ค.
259278
AppleTokenResDto appleTokenResDto = appleService.getAppleToken(reqDto.getSocialCode());
@@ -267,6 +286,7 @@ public SwitchAccountResDto switchAccount(@Valid SwitchAccountReqDto reqDto, Cust
267286

268287
// ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํšŒ์›์ด๋ฉด ์ „ํ™˜ ๋ฐฉ์ง€
269288
if(userRepository.existsBySocialId(socialId)) {
289+
log.warn("Switch failed - socialId already exists: {}", socialId);
270290
throw new CustomException(ErrorCode.SOCIAL_ALREADY_EXISTS);
271291
}
272292

@@ -276,8 +296,12 @@ public SwitchAccountResDto switchAccount(@Valid SwitchAccountReqDto reqDto, Cust
276296

277297
// ์ƒˆ๋กญ๊ฒŒ ์ „ํ™˜ํ•˜๋Š” ์œ ์ €์ด๋ฉด ๊ธฐ์กด Role: GUEST -> USER, GUEST -> APPLE
278298
currentUser.switchAccount(email, Role.USER, SocialType.APPLE, socialId);
299+
userRepository.save(currentUser);
279300
accessToken = jwtUtil.createAccessToken(socialId, Role.USER, SocialType.APPLE);
280301
refreshToken = jwtUtil.createRefreshToken(socialId);
302+
303+
log.info("Switch success - userId: {}, newSocialType: APPLE, socialId: {}",
304+
currentUser.getId(), socialId);
281305
}
282306
}
283307

โ€Žsrc/main/java/com/example/ForDay/domain/user/entity/User.javaโ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void withdraw() {
121121
}
122122

123123
if (this.socialId != null && !this.socialId.startsWith("withdrawn_")) {
124-
this.socialId = "withdrawn_" + this.socialId;
124+
this.socialId = "withdrawn_" + this.socialId + this.id.substring(0, 8);
125125
}
126126

127127
this.profileImageUrl = null;

0 commit comments

Comments
ย (0)