26 lines
615 B
Go
26 lines
615 B
Go
package handler
|
|
|
|
import (
|
|
"kra/internal/server/middleware"
|
|
"kra/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Session struct{ tokens *service.TokenService }
|
|
|
|
func NewSession(tokens *service.TokenService) *Session { return &Session{tokens: tokens} }
|
|
func (h *Session) Logout(c *gin.Context) {
|
|
token := middleware.RequestToken(c, false)
|
|
if token == "" {
|
|
NoAuth(c, "未登录或非法访问")
|
|
return
|
|
}
|
|
if err := h.tokens.BlacklistToken(c.Request.Context(), token); err != nil {
|
|
Fail(c, "jwt作废失败")
|
|
return
|
|
}
|
|
SetTokenCookie(c, "", -1)
|
|
Write(c, CodeSuccess, gin.H{}, "jwt作废成功")
|
|
}
|