Skip to content

Commit a8642f4

Browse files
feitianbubuclaude
andcommitted
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>
1 parent 057ad2e commit a8642f4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

server/api/v1/system/sys_user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func (b *BaseApi) SetUserAuthority(c *gin.Context) {
264264
}
265265
c.Header("new-token", token)
266266
c.Header("new-expires-at", strconv.FormatInt(claims.ExpiresAt.Unix(), 10))
267-
utils.SetToken(c, token, int((claims.ExpiresAt.Unix()-time.Now().Unix())/60))
267+
utils.SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
268268
response.OkWithMessage("修改成功", c)
269269
}
270270

server/utils/claims.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func GetToken(c *gin.Context) string {
4949
global.GVA_LOG.Error("重新写入cookie token失败,未能成功解析token,请检查请求头是否存在x-token且claims是否为规定结构")
5050
return token
5151
}
52-
SetToken(c, token, int((claims.ExpiresAt.Unix()-time.Now().Unix())/60))
52+
SetToken(c, token, int(claims.ExpiresAt.Unix()-time.Now().Unix()))
5353
}
5454
return token
5555
}

0 commit comments

Comments
 (0)