Skip to content

Commit c63c112

Browse files
.cn domain cookies
1 parent fa832cf commit c63c112

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

backend/server/src/handler/auth.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,20 @@ pub async fn google_callback(
127127
"devsoc.app"
128128
};
129129

130-
let cookie = Cookie::build(("auth_token", token))
130+
let cookie = Cookie::build(("auth_token", token.clone()))
131131
.http_only(true) // Prevent JavaScript access
132132
.expires(Expiration::DateTime(OffsetDateTime::now_utc() + time::Duration::days(5))) // Set an expiration time of 5 days, TODO: read from env?
133133
.secure(!state.is_dev_env) // Send only over HTTPS, comment out for testing
134134
.domain(domain)
135135
.path("/"); // Available for all paths
136136

137+
let cn_cookie = Cookie::build(("auth_token", token))
138+
.http_only(true)
139+
.expires(Expiration::DateTime(OffsetDateTime::now_utc() + time::Duration::days(5)))
140+
.secure(!state.is_dev_env)
141+
.domain("devsoc.cn")
142+
.path("/");
143+
137144
let redirect_root = if state.is_dev_env {
138145
"http://localhost:3000"
139146
} else {
@@ -149,8 +156,8 @@ pub async fn google_callback(
149156
None => format!("{redirect_root}/dashboard"),
150157
};
151158

152-
// Add the cookie and redirect
153-
Ok((jar.add(cookie), Redirect::to(redirect_url.as_str())))
159+
// Add cookies and redirect
160+
Ok((jar.add(cookie).add(cn_cookie), Redirect::to(redirect_url.as_str())))
154161
}
155162

156163
pub async fn logout(
@@ -170,13 +177,20 @@ pub async fn logout(
170177
.domain(domain)
171178
.path("/");
172179

180+
let empty_cn_cookie= Cookie::build(("auth_token", ""))
181+
.http_only(true) // Prevent JavaScript access
182+
.expires(Expiration::DateTime(OffsetDateTime::now_utc() + time::Duration::days(5)))
183+
.secure(!state.is_dev_env)
184+
.domain("devsoc.cn")
185+
.path("/");
186+
173187
let redirect = if state.is_dev_env {
174188
"http://localhost:3000"
175189
} else {
176190
"https://chaos.devsoc.app"
177191
};
178192

179-
Ok((jar.remove(empty_cookie), Redirect::to(redirect)))
193+
Ok((jar.remove(empty_cookie).remove(empty_cn_cookie), Redirect::to(redirect)))
180194
}
181195

182196
pub struct DevLoginHandler;

0 commit comments

Comments
 (0)