Skip to content

Commit 58e1562

Browse files
authored
merge: 인증 시 쿠키에 Domain 추가
2 parents 25a6072 + d65889b commit 58e1562

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ JWT_REFRESH_TOKEN_SECRET=string
3030
JWT_REFRESH_TOKEN_EXPIRATION=number
3131
SPRINGDOC_ENABLED=boolean
3232
SWAGGER_ENABLED=boolean
33+
SERVER_COOKIE_DOMAIN=string

src/main/kotlin/com/team/incube/gsmc/v3/global/common/cookie/CookieUtil.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.team.incube.gsmc.v3.global.common.cookie
22

3+
import org.springframework.beans.factory.annotation.Value
34
import org.springframework.core.env.Environment
45
import org.springframework.http.ResponseCookie
56
import org.springframework.stereotype.Component
@@ -13,6 +14,9 @@ class CookieUtil(
1314
companion object {
1415
private const val ACCESS_TOKEN_COOKIE_NAME = "accessToken"
1516
private const val REFRESH_TOKEN_COOKIE_NAME = "refreshToken"
17+
18+
@Value("\${server.cookie.domain}")
19+
private lateinit var cookieDomain: String
1620
}
1721

1822
private val isProduction: Boolean
@@ -30,7 +34,11 @@ class CookieUtil(
3034
.sameSite("Strict")
3135
.path("/")
3236
.maxAge(maxAge)
33-
.build()
37+
.apply {
38+
if (isProduction) {
39+
domain(cookieDomain)
40+
}
41+
}.build()
3442

3543
fun createAuthCookies(
3644
accessToken: String,

src/main/resources/application.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ spring:
8383
server:
8484
port: ${SERVER_PORT:8080}
8585
shutdown: graceful
86+
cookie:
87+
domain: ${SERVER_COOKIE_DOMAIN:localhost}
8688
management:
8789
endpoints:
8890
web:

0 commit comments

Comments
 (0)