fix: fixed bug for jwt token expire caculation

This commit is contained in:
RockYang
2023-09-12 10:49:55 +08:00
parent 9afe4aea4b
commit d825b9ec26
3 changed files with 17 additions and 8 deletions

View File

@@ -160,10 +160,9 @@ func (h *UserHandler) Login(c *gin.Context) {
})
// 创建 token
expired := time.Now().Add(time.Second * time.Duration(h.App.Config.Session.MaxAge))
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"user_id": user.Id,
"expired": expired,
"expired": time.Now().Add(time.Second * time.Duration(h.App.Config.Session.MaxAge)).Unix(),
})
tokenString, err := token.SignedString([]byte(h.App.Config.Session.SecretKey))
if err != nil {
@@ -182,8 +181,8 @@ func (h *UserHandler) Login(c *gin.Context) {
// Logout 注 销
func (h *UserHandler) Logout(c *gin.Context) {
sessionId := c.GetHeader(types.ChatTokenHeader)
token := c.GetHeader(types.UserAuthHeader)
if _, err := h.redis.Del(c, token).Result(); err != nil {
key := h.GetUserKey(c)
if _, err := h.redis.Del(c, key).Result(); err != nil {
logger.Error("error with delete session: ", err)
}
// 删除 websocket 会话列表