Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Feat: 카카오 로그인 완료 후 kaboo.site/join 으로 redirect #12

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseCookie;
import org.springframework.security.core.Authentication;
Expand All @@ -11,7 +10,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;

import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import kaboo.kaboo_auth.domain.dto.response.LoginSucessResponse;
Expand All @@ -32,9 +30,6 @@ public class LoginSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
private final int accessTokenValidTime = 10 * 60; // 유효기간 : 10분
private final int refreshTokenValidTime = 10 * 24 * 60 * 60; // 유효기간 : 10일

@Value("${AUTH.REDIRECT_URL}")
private String redirectURL;

private ResponseCookie createCookie(String key, String value, int maxAge) {
return ResponseCookie.from(key, value)
.maxAge(maxAge)
Expand All @@ -60,15 +55,20 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
ObjectMapper objectMapper = new ObjectMapper();
String jsonResponse = objectMapper.writeValueAsString(loginSucessResponse);

response.addHeader(HttpHeaders.SET_COOKIE, createCookie("username", username, refreshTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE, createCookie("accessToken", accessToken, accessTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE, createCookie("refreshToken", refreshToken, refreshTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE,
createCookie("username", username, refreshTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE,
createCookie("accessToken", accessToken, accessTokenValidTime).toString());
response.addHeader(HttpHeaders.SET_COOKIE,
createCookie("refreshToken", refreshToken, refreshTokenValidTime).toString());

// 응답 설정
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");

// JSON 응답을 출력 스트림에 작성
response.getWriter().write(jsonResponse);

response.sendRedirect("https://kaboo.site/join");
}
}
Loading