Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug by overwriting existing system cookie #1304

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions web/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ 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), // 设置为过期时间
MaxAge: -1, // 立即删除该 Cookie
HttpOnly: true,
}
// 设置过期的 Cookie
http.SetCookie(w, &expiredCookie)
http.SetCookie(w, cookieInSystem)

// 重定向用户到登录页面
http.Redirect(w, r, "./login", http.StatusFound)
Expand Down