🎨优化

This commit is contained in:
coward 2024-07-12 17:18:04 +08:00
parent 9af89ee41f
commit 3e1d3d63d0
3 changed files with 7 additions and 4 deletions

View File

@ -68,7 +68,10 @@ func (JwtComponent) GenerateToken(userId, secret string, times ...time.Time) (to
return "", nil, errors.New("生成token失败")
}
client.Redis.Set(context.Background(), fmt.Sprintf("%s:%s", constant.UserToken, userId), token, 7*time.Hour)
client.Redis.Set(context.Background(),
fmt.Sprintf("%s:%s", constant.UserToken, userId),
token,
time.Duration(expireTime.Sub(time.Now()).Abs().Seconds())*time.Second)
return
}

View File

@ -1,6 +1,6 @@
package constant
const (
Captcha = "captcha:"
UserToken = "token:"
Captcha = "captcha"
UserToken = "token"
)

View File

@ -65,7 +65,7 @@ func Authorization() gin.HandlerFunc {
// 生成一个新token
secret := component.JWT().GenerateSecret(user.Password, uuid.NewString(), time.Now().Local().String())
tokenStr, _, err := component.JWT().GenerateToken(user.Id, secret, userClaims.ExpiresAt.Time, userClaims.IssuedAt.Time)
tokenStr, _, err := component.JWT().GenerateToken(user.Id, secret, userClaims.ExpiresAt.Time, time.Now().Local())
if err != nil {
response.R(c).AuthorizationFailed("校验失败")
c.Abort()