Skip to content

Commit

Permalink
[Fix] oauth success url 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed Oct 5, 2024
1 parent 11a3b8c commit 76e2ee5
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.appcenter.BJJ.jwt.JwtProvider;
import com.appcenter.BJJ.jwt.UserDetailsImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -21,26 +20,24 @@
public class OAuth2SuccessHandler implements AuthenticationSuccessHandler {
private final JwtProvider jwtProvider;
//로그인 성공 및 토큰 발급 및 redirect url
@Value("${spring.server.host}")
private String domain;
@Value("${spring.oauth2.url.sign_in}")
private String signInUrl;
@Value("${spring.oauth2.url.sign_up}")
private String signUpUrl;

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
log.info("OAuth2SuccessHandler 진입");
UserDetailsImpl userDetails = (UserDetailsImpl) authentication.getPrincipal();
String token = jwtProvider.generateToken(authentication, JwtProvider.validAccessTime);
String redirectUrl;
if (userDetails.getMember().getRole().equals("ROLE_GUEST")) {
log.info("OAuth2SuccessHandler-onAuthenticationSuccess: 회원가입으로 이동");
redirectUrl = UriComponentsBuilder.fromHttpUrl(domain + signUpUrl)
redirectUrl = UriComponentsBuilder.fromHttpUrl(signUpUrl)
.queryParam("token", token).toUriString();
} else {
log.info("OAuth2SuccessHandler-onAuthenticationSuccess: 로그인으로 이동");
redirectUrl = UriComponentsBuilder.fromHttpUrl(domain + signInUrl)
redirectUrl = UriComponentsBuilder.fromHttpUrl(signInUrl)
.queryParam("token", token).toUriString();
}
response.sendRedirect(redirectUrl);
Expand Down

0 comments on commit 76e2ee5

Please sign in to comment.