From a8642f45823f112ae6982715cd365027f59e4ad9 Mon Sep 17 00:00:00 2001 From: feitianbubu Date: Fri, 7 Nov 2025 10:51:18 +0800 Subject: [PATCH] fix: correct cookie maxAge calculation by using seconds instead of minutes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- server/api/v1/system/sys_user.go | 2 +- server/utils/claims.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/api/v1/system/sys_user.go b/server/api/v1/system/sys_user.go index 9169f06cee..ae6ab022b9 100644 --- a/server/api/v1/system/sys_user.go +++ b/server/api/v1/system/sys_user.go @@ -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) } diff --git a/server/utils/claims.go b/server/utils/claims.go index 2a6308e8a1..f69796718c 100644 --- a/server/utils/claims.go +++ b/server/utils/claims.go @@ -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 }