Skip to content

Commit

Permalink
chore: clean unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed May 16, 2024
1 parent 70943ed commit 2bb0f4c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
15 changes: 6 additions & 9 deletions internal/pkg/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/tokenStore/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2bb0f4c

Please sign in to comment.