tianyuan-api-server/apps/gateway/internal/handler/auth/logouthandler.go

24 lines
587 B
Go
Raw Normal View History

2024-10-02 00:57:17 +08:00
package auth
import (
"net/http"
"time"
xhttp "github.com/zeromicro/x/http"
"tianyuan-api/apps/gateway/internal/svc"
)
func LogoutHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// 设置空的JWT Cookie覆盖之前的JWT
http.SetCookie(w, &http.Cookie{
Name: "Authorization", // 你的JWT cookie名
Value: "", // 清空cookies
Path: "/",
HttpOnly: true,
Expires: time.Unix(0, 0), // 过期时间设置为过去
})
xhttp.JsonBaseResponseCtx(r.Context(), w, nil)
}
}