mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-04 19:32:17 +08:00 
			
		
		
		
	fix: token update expire time
This commit is contained in:
		
							parent
							
								
									75de7b75a1
								
							
						
					
					
						commit
						2ad6f7ba59
					
				@ -55,7 +55,6 @@ func (a *authDatabase) SetTokenMapByUidPid(ctx context.Context, userID string, p
 | 
			
		||||
 | 
			
		||||
// Create Token.
 | 
			
		||||
func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformID int) (string, error) {
 | 
			
		||||
	isCreate := true // flag is create or update
 | 
			
		||||
	tokens, err := a.cache.GetTokensWithoutError(ctx, userID, platformID)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
@ -66,9 +65,6 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI
 | 
			
		||||
		if err != nil || v != constant.NormalToken {
 | 
			
		||||
			deleteTokenKey = append(deleteTokenKey, k)
 | 
			
		||||
		}
 | 
			
		||||
		if v == constant.NormalToken {
 | 
			
		||||
			isCreate = false
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if len(deleteTokenKey) != 0 {
 | 
			
		||||
		err = a.cache.DeleteTokenByUidPid(ctx, userID, platformID, deleteTokenKey)
 | 
			
		||||
@ -84,16 +80,8 @@ func (a *authDatabase) CreateToken(ctx context.Context, userID string, platformI
 | 
			
		||||
		return "", errs.WrapMsg(err, "token.SignedString")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if isCreate {
 | 
			
		||||
		// should create,should specify expiration time
 | 
			
		||||
		if err = a.cache.SetTokenFlagEx(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		// should update
 | 
			
		||||
		if err = a.cache.SetTokenFlag(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil {
 | 
			
		||||
			return "", err
 | 
			
		||||
		}
 | 
			
		||||
	if err = a.cache.SetTokenFlagEx(ctx, userID, platformID, tokenString, constant.NormalToken); err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
	return tokenString, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user