fix: correct cookie maxAge calculation by using seconds instead of minutes

The SetToken function expects maxAge in seconds (standard for HTTP cookies), but the code was incorrectly dividing by 60, causing cookies to expire 60 times faster than intended.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
feitianbubu
2025-11-07 10:51:18 +08:00
parent 057ad2eeeb
commit a8642f4582
2 changed files with 2 additions and 2 deletions

View File

@@ -264,7 +264,7 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
}
c.Header("new-token", token)
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt.Unix(), 10))
utils.SetToken(c, token, int((claims.ExpiresAt.Unix()-time.Now().Unix())/60))
utils.SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
response.OkWithMessage("修改成功", c)
}

View File

@@ -49,7 +49,7 @@ func GetToken(c *gin.Context) string {
global.GVA_LOG.Error("重新写入cookie token失败,未能成功解析token,请检查请求头是否存在x-token且claims是否为规定结构")
return token
}
SetToken(c, token, int((claims.ExpiresAt.Unix()-time.Now().Unix())/60))
SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
}
return token
}