@@ -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
0 commit comments