tianyuan-api-server/apps/gateway/internal/handler/auth/logouthandler.go
2024-10-02 00:57:17 +08:00

24 lines
587 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}