From 2bb0f4cb00568d46734ed2515272b4b409a98afd Mon Sep 17 00:00:00 2001 From: Mmx233 Date: Thu, 16 May 2024 22:25:06 +0800 Subject: [PATCH] chore: clean unused code --- internal/pkg/jwt/jwt.go | 15 ++++++--------- pkg/tokenStore/node.go | 1 + 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/pkg/jwt/jwt.go b/internal/pkg/jwt/jwt.go index 109e82a..a33d769 100644 --- a/internal/pkg/jwt/jwt.go +++ b/internal/pkg/jwt/jwt.go @@ -100,18 +100,18 @@ func ParseTokenAndVerify[C jwtClaims.ClaimsUser](Type, token string, target C) ( } // GenerateUserToken 生成后台 Token -func GenerateUserToken(uid uint, lid uint64, name string, groups []string, valid time.Duration) (string, error) { +func GenerateUserToken(uid uint, loginRecordID uint64, name string, groups []string, valid time.Duration) (string, error) { userClaims, err := NewUserClaims(uid, User, valid) if err != nil { return "", err } claims := &jwtClaims.UserToken{ - ID: lid, + ID: loginRecordID, UserClaims: userClaims, Name: name, Groups: groups, } - err = redis.NewRecordedToken().CreateStorePointWithID(context.Background(), lid, valid, nil) + err = redis.NewRecordedToken().CreateStorePointWithID(context.Background(), loginRecordID, valid, nil) if err != nil { return "", err } @@ -124,9 +124,6 @@ func ParseUserToken(token string) (*jwtClaims.UserToken, bool, error) { if err != nil || !valid { return claims, valid, err } - if err != nil { - return nil, false, err - } return claims, true, redis.NewRecordedToken().NewStorePoint(claims.ID).Get(context.Background(), nil) } @@ -237,18 +234,18 @@ func ParseU2fToken(token, ip string) (bool, error) { return true, nil } -func GenerateRefreshToken(uid uint, lid uint64, appCode, payload string, valid time.Duration) (string, *jwtClaims.RefreshToken, error) { +func GenerateRefreshToken(uid uint, loginRecordID uint64, appCode, payload string, valid time.Duration) (string, *jwtClaims.RefreshToken, error) { userClaims, err := NewUserClaims(uid, Refresh, valid) if err != nil { return "", nil, err } claims := jwtClaims.RefreshToken{ - ID: lid, + ID: loginRecordID, UserClaims: userClaims, AppCode: appCode, Payload: payload, } - err = redis.NewRecordedToken().CreateStorePointWithID(context.Background(), lid, valid, nil) + err = redis.NewRecordedToken().CreateStorePointWithID(context.Background(), loginRecordID, valid, nil) if err != nil { return "", nil, err } diff --git a/pkg/tokenStore/node.go b/pkg/tokenStore/node.go index fd963ec..546355a 100644 --- a/pkg/tokenStore/node.go +++ b/pkg/tokenStore/node.go @@ -67,5 +67,6 @@ func (node NodeWithClient) GenID(ctx context.Context) (uint64, error) { } tokenID := node.TokenID.Add(1) tokenID = (tokenID << 18) + (node.ID << 10) + node.IDTimeMark + fmt.Println(tokenID) return tokenID, nil }