From 96b407ef89ecd462070fe3c5ab8731afa7ff0df4 Mon Sep 17 00:00:00 2001 From: hujie Date: Fri, 6 Mar 2026 12:03:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20jwt=E6=B7=BB=E5=8A=A0role=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/jwt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/jwt.go b/utils/jwt.go index 4d724bd..f2453f1 100644 --- a/utils/jwt.go +++ b/utils/jwt.go @@ -152,8 +152,9 @@ func (j *JWT) ValidateToken(tokenString string) bool { // secretKey: 密钥 // userID: 用户 ID // userName: 用户名 +// role: 用户角色 // expires: 过期时间(小时) -func CreateToken(secretKey, userID, userName string, expires int) (string, error) { +func CreateToken(secretKey, userID, userName string, role, expires int) (string, error) { jwtUtil := NewJWT(JWTConfig{ SecretKey: secretKey, ExpiresTime: time.Duration(expires) * time.Hour, @@ -162,6 +163,7 @@ func CreateToken(secretKey, userID, userName string, expires int) (string, error claims := &CustomClaims{ UserID: userID, UserName: userName, + Role: role, } return jwtUtil.GenerateToken(claims)