99import jakarta .servlet .http .HttpServletResponse ;
1010import jakarta .servlet .http .HttpSession ;
1111import lombok .RequiredArgsConstructor ;
12+ import org .springframework .beans .factory .annotation .Value ;
13+ import org .springframework .http .HttpHeaders ;
1214import org .springframework .http .ResponseEntity ;
1315import org .springframework .security .core .annotation .AuthenticationPrincipal ;
1416import org .springframework .util .StringUtils ;
1517import org .springframework .web .bind .annotation .*;
18+ import org .springframework .web .util .UriComponentsBuilder ;
1619
20+ import java .io .IOException ;
21+ import java .net .URI ;
22+ import java .net .URLEncoder ;
23+ import java .nio .charset .StandardCharsets ;
24+ import java .util .Base64 ;
1725import java .util .HashMap ;
1826import java .util .Map ;
1927
@@ -32,21 +40,27 @@ public class AuthController {
3240 * @return 로그인 성공 응답과 JWT access token
3341 */
3442 @ GetMapping ("/success" )
35- public ResponseEntity <CommonResponse > loginSuccess (HttpSession session ) {
43+ public ResponseEntity <Void > loginSuccess (HttpSession session ) throws IOException {
3644 // 세션에서 데이터 읽기
3745 String accessToken = (String ) session .getAttribute ("accessToken" );
3846 Member member = (Member ) session .getAttribute ("member" );
3947
40- // 소셜 로그인 성공 응답 객체 생성
41- Map <String , Object > result = new HashMap <>();
42- result .put ("id" , member .getId ());
43- result .put ("username" , member .getName ());
44- result .put ("email" , member .getEmail ());
45- result .put ("accessToken" , accessToken );
48+ // 프론트엔드 엔드포인트로 리다이렉트
49+ String baseFrontendUrl = "https://localhost:5173" ;
50+ String encodedUsername = Base64 .getEncoder ().encodeToString (member .getName ().getBytes (StandardCharsets .UTF_8 ));
4651
47- CommonResponse response = new CommonResponse (
48- HttpStatus .OK , "소셜 로그인에 성공했습니다." , result );
49- return ResponseEntity .ok (response );
52+ HttpHeaders headers = new HttpHeaders ();
53+ headers .setLocation (URI .create (baseFrontendUrl + "/sign-up" ));
54+
55+ // 쿠키로 사용자 데이터 전달
56+ headers .add (HttpHeaders .SET_COOKIE , "accessToken=" + accessToken + "; Secure; SameSite=None; Path=/; Max-Age=3600" );
57+ headers .add (HttpHeaders .SET_COOKIE , "id=" + member .getId () + "; Secure; SameSite=None; Path=/; Max-Age=3600" );
58+ headers .add (HttpHeaders .SET_COOKIE , "username=" + encodedUsername + "; Secure; SameSite=None; Path=/; Max-Age=3600" );
59+ headers .add (HttpHeaders .SET_COOKIE , "email=" + member .getEmail () + "; Secure; SameSite=None; Path=/; Max-Age=3600" );
60+
61+ return ResponseEntity .status (HttpStatus .MOVED_PERMANENTLY )
62+ .headers (headers )
63+ .body (null );
5064 }
5165
5266 /**
0 commit comments