Fix bug by overwriting existing system cookie (#1304)
Some checks failed
test / test (amd64) (push) Has been cancelled
test / test (arm64) (push) Has been cancelled

This commit is contained in:
luopc 2024-10-31 23:36:14 +08:00 committed by GitHub
parent 2b9bda3dce
commit 5f0d7eb183
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,9 +6,9 @@ import (
)
func Logout(w http.ResponseWriter, r *http.Request) {
// 创建一个过期的 Cookie 来清除客户端的身份认证 Cookie
expiredCookie := http.Cookie{
Name: cookieName, // 假设你的身份验证使用的是名为 "auth" 的 Cookie
// 覆盖cookieInSystem
cookieInSystem = &http.Cookie{
Name: cookieName,
Value: "",
Path: "/",
Expires: time.Unix(0, 0), // 设置为过期时间
@ -16,7 +16,7 @@ func Logout(w http.ResponseWriter, r *http.Request) {
HttpOnly: true,
}
// 设置过期的 Cookie
http.SetCookie(w, &expiredCookie)
http.SetCookie(w, cookieInSystem)
// 重定向用户到登录页面
http.Redirect(w, r, "./login", http.StatusFound)