Skip to content

Commit 72b6bdd

Browse files
authored
[BUG] 프론트 연동 오류
2 parents 80e3964 + a414f43 commit 72b6bdd

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
package com.sudo.railo.auth.util;
22

3+
import org.springframework.beans.factory.annotation.Value;
34
import org.springframework.stereotype.Component;
45

5-
import jakarta.servlet.http.Cookie;
66
import jakarta.servlet.http.HttpServletResponse;
77

88
@Component
99
public class CookieManager {
1010

1111
private static final String COOKIE_PATH = "/";
1212

13+
@Value("${cookie.domain}")
14+
private String cookieDomain;
15+
1316
public void setCookie(HttpServletResponse response, String name, String value, int maxAge) {
14-
Cookie cookie = createCookie(name, value, maxAge);
15-
response.addCookie(cookie);
17+
String cookieHeader = String.format(
18+
"%s=%s; Max-Age=%d; Path=%s; Domain=%s; Secure; HttpOnly; SameSite=None",
19+
name, value, maxAge, COOKIE_PATH, cookieDomain
20+
);
21+
response.setHeader("Set-Cookie", cookieHeader); // 중복 방지: addHeader → setHeader
1622
}
1723

1824
public void removeCookie(HttpServletResponse response, String name) {
19-
Cookie cookie = createCookie(name, null, 0);
20-
response.addCookie(cookie);
21-
}
22-
23-
private Cookie createCookie(String name, String value, int maxAge) {
24-
Cookie cookie = new Cookie(name, value);
25-
cookie.setMaxAge(maxAge);
26-
cookie.setSecure(true);
27-
cookie.setHttpOnly(true);
28-
cookie.setPath(COOKIE_PATH);
29-
30-
return cookie;
25+
String cookieHeader = String.format(
26+
"%s=; Max-Age=0; Path=%s; Domain=%s; Secure; HttpOnly; SameSite=None",
27+
name, COOKIE_PATH, cookieDomain
28+
);
29+
response.setHeader("Set-Cookie", cookieHeader); // 중복 방지
3130
}
3231
}

src/main/resources/application-dev.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ cors:
7070
jwt:
7171
secret: ${JWT_KEY}
7272

73+
cookie:
74+
domain: localhost
75+
7376
booking:
7477
expiration:
7578
reservation: 10

src/main/resources/application-prod.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ train:
6363
ratio: 0.15
6464

6565
cors:
66-
allowed-origins: http://localhost:3000, https://www.raillo.shop
66+
allowed-origins: https://www.raillo.shop
6767
allowed-methods: GET, POST, PUT, DELETE
6868
allowed-headers: Access-Control-Allow-Origin, Content-type, Access-Control-Allow-Headers, Authorization, X-Requested-With
6969

7070
jwt:
7171
secret: ${JWT_KEY}
7272

73+
cookie:
74+
domain: .raillo.shop
75+
7376
booking:
7477
expiration:
7578
reservation: 10

src/test/resources/application-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ cors:
5555
booking:
5656
expiration:
5757
reservation: 1
58+
59+
cookie:
60+
domain: .test

0 commit comments

Comments
 (0)