Skip to content
Merged
Show file tree
Hide file tree
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 @@ -20,13 +20,14 @@
@RequiredArgsConstructor
@Component
public class CustomOAuth2SuccessHandler extends SimpleUrlAuthenticationSuccessHandler {

private final CookieUtil cookieUtil;
private final JwtUtil jwtUtil;

@Value("${redirect.url}")
private String redirectUrl;

private static final String[] DOMAINS = {"localhost", ".sonisori.site"};

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
Expand All @@ -42,7 +43,9 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo
}

private void addCookies(HttpServletResponse response, String tokenName, String tokenValue) {
String cookie = cookieUtil.createCookie(tokenName, tokenValue, "localhost").toString();
response.addHeader("Set-Cookie", cookie);
for (String domain : DOMAINS) {
String cookie = cookieUtil.createCookie(tokenName, tokenValue, domain).toString();
response.addHeader("Set-Cookie", cookie);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.addAllowedOrigin("http://localhost:5173");
configuration.addAllowedOrigin("https://www.sonisori.site");
configuration.addAllowedMethod("*");
configuration.addAllowedHeader("*");
configuration.setAllowCredentials(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class UserController {
private final UserService userService;
private final CookieUtil cookieUtil;
private final JwtUtil jwtUtil;
private static final String[] DOMAINS = {"localhost", ".sonisori.site"};

@PostMapping("/auth/signup")
public ResponseEntity<Void> signUp(@RequestBody @Valid SignUpRequest signUpRequest) {
Expand Down Expand Up @@ -132,12 +133,16 @@ public ResponseEntity<Void> reissue(@AuthenticationPrincipal CustomUserDetails u
}

private void addCookies(HttpServletResponse response, String tokenName, String tokenValue) {
String cookie = cookieUtil.createCookie(tokenName, tokenValue, "localhost").toString();
response.addHeader("Set-Cookie", cookie);
for (String domain : DOMAINS) {
String cookie = cookieUtil.createCookie(tokenName, tokenValue, domain).toString();
response.addHeader("Set-Cookie", cookie);
}
}

private void deleteCookies(HttpServletResponse response, String cookieName) {
String cookie = cookieUtil.clearCookie(cookieName, "localhost").toString();
response.addHeader("Set-Cookie", cookie);
private void deleteCookies(HttpServletResponse response, String tokenName) {
for (String domain : DOMAINS) {
String cookie = cookieUtil.clearCookie(tokenName, domain).toString();
response.addHeader("Set-Cookie", cookie);
}
}
}
Loading