first commit
This commit is contained in:
23
apps/gateway/internal/handler/auth/logouthandler.go
Normal file
23
apps/gateway/internal/handler/auth/logouthandler.go
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user