Skip to content

Commit

Permalink
chore: 修正token过期bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tangtanglove committed Jan 10, 2025
1 parent cd04ccb commit b4a1109
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
AppName = "QuarkGo"

// 版本号
Version = "3.8.0"
Version = "3.8.1"

// 包名
PkgName = "github.com/quarkcloudio/quark-go/v3"
Expand Down
16 changes: 8 additions & 8 deletions service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewAuthService(ctx *quark.Context) *AuthService {
}

// 生成用户token
func (p *AuthService) MakeToken(user model.User, guardName string, expire int) (token string, err error) {
func (p *AuthService) MakeToken(user model.User, guardName string, expireSecond int) (token string, err error) {
userClaims := &dto.UserClaims{
Id: user.Id,
Username: user.Username,
Expand All @@ -32,11 +32,11 @@ func (p *AuthService) MakeToken(user model.User, guardName string, expire int) (
Avatar: user.Avatar,
GuardName: guardName,
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(expire) * time.Second)), // 过期时间,默认24小时
IssuedAt: jwt.NewNumericDate(time.Now()), // 颁发时间
NotBefore: jwt.NewNumericDate(time.Now()), // 不早于时间
Issuer: "QuarkCloud", // 颁发人
Subject: "UserToken", // 主题信息
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Duration(expireSecond) * time.Second)), // 过期时间,默认24小时
IssuedAt: jwt.NewNumericDate(time.Now()), // 颁发时间
NotBefore: jwt.NewNumericDate(time.Now()), // 不早于时间
Issuer: "QuarkCloud", // 颁发人
Subject: "UserToken", // 主题信息
},
}
return p.ctx.JwtToken(userClaims)
Expand All @@ -51,7 +51,7 @@ func (p *AuthService) AdminLogin(username string, password string) (token string
if !hash.Check(user.Password, password) {
return "", errors.New("用户名或密码错误")
}
token, err = p.MakeToken(user, "admin", 24*60)
token, err = p.MakeToken(user, "admin", 24*60*60)
if err != nil {
return
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (p *AuthService) UserLogin(username string, password string) (token string,
if !hash.Check(user.Password, password) {
return "", errors.New("用户名或密码错误")
}
token, err = p.MakeToken(user, "user", 24*60)
token, err = p.MakeToken(user, "user", 24*60*60)
if err != nil {
return
}
Expand Down

0 comments on commit b4a1109

Please sign in to comment.