Skip to content

Commit

Permalink
[FEAT] OAuth2SuccessHandler 요청 헤더에 따른 baseUrl 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
bbabbi committed Dec 1, 2024
1 parent 225e227 commit 667f0e6
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.autorepo.server.domain.user.service;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.autorepo.server.domain.token.dto.TokenResponse;
import org.autorepo.server.domain.token.service.TokenService;
import org.autorepo.server.domain.user.entity.User;
import org.autorepo.server.domain.user.repository.UserRepository;
Expand Down Expand Up @@ -44,8 +42,12 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
// RefreshToken 저장
tokenService.saveRefreshToken(user.getUserId(), jwtRefreshToken);

// 요청의 Origin 헤더로 baseUrl 설정
String origin = request.getHeader("Origin");
String clientBaseUrl = (origin != null) ? origin : "http://localhost:3000";

// 클라이언트로 리다이렉트
String redirectUrl = "http://localhost:3000/oauth2/success?accessToken=" + jwtAccessToken + "&refreshToken=" + jwtRefreshToken;
String redirectUrl = clientBaseUrl + "/oauth2/success?accessToken=" + jwtAccessToken + "&refreshToken=" + jwtRefreshToken;
response.sendRedirect(redirectUrl);
}
}

0 comments on commit 667f0e6

Please sign in to comment.