Skip to content

Commit f082289

Browse files
ExquisiteCoreclaude
andcommitted
fix: 修改 Cookie Path 为 / 以解决存储问题
将 refresh_token Cookie 的 Path 从 /api/auth 改为 /, 确保 Cookie 在所有路径下可用,避免路径不匹配导致的存储问题。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d032f45 commit f082289

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

backend/src/middleware/auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ pub fn build_refresh_cookie(token: &str) -> String {
156156
if is_dev {
157157
// 开发环境:不设置 Secure,使用 SameSite=Lax
158158
format!(
159-
"refresh_token={}; HttpOnly; SameSite=Lax; Path=/api/auth; Max-Age={}",
159+
"refresh_token={}; HttpOnly; SameSite=Lax; Path=/; Max-Age={}",
160160
token, max_age
161161
)
162162
} else {
163163
// 生产环境:设置 Domain 使 Cookie 在主域下共享,避免被浏览器当作第三方 Cookie 拦截
164164
format!(
165-
"refresh_token={}; HttpOnly; Secure; SameSite=None; Domain=.exquisitecore.xyz; Path=/api/auth; Max-Age={}",
165+
"refresh_token={}; HttpOnly; Secure; SameSite=None; Domain=.exquisitecore.xyz; Path=/; Max-Age={}",
166166
token, max_age
167167
)
168168
}
@@ -174,9 +174,9 @@ pub fn build_clear_refresh_cookie() -> String {
174174
let is_dev = config.cors.allowed_origins.iter().all(|o| o.contains("localhost"));
175175

176176
if is_dev {
177-
"refresh_token=; HttpOnly; SameSite=Lax; Path=/api/auth; Max-Age=0".to_string()
177+
"refresh_token=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0".to_string()
178178
} else {
179-
"refresh_token=; HttpOnly; Secure; SameSite=None; Domain=.exquisitecore.xyz; Path=/api/auth; Max-Age=0".to_string()
179+
"refresh_token=; HttpOnly; Secure; SameSite=None; Domain=.exquisitecore.xyz; Path=/; Max-Age=0".to_string()
180180
}
181181
}
182182

0 commit comments

Comments
 (0)