Skip to content

Commit

Permalink
Fix bug by overwriting existing system cookie (#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpcheng1208 authored Oct 31, 2024
1 parent 2b9bda3 commit 5f0d7eb
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 5f0d7eb

Please sign in to comment.