remove invalid token

This commit is contained in:
Gordon
2021-12-28 10:59:01 +08:00
parent 30024c9814
commit 292a8620e0
3 changed files with 24 additions and 3 deletions
+16
View File
@@ -6,6 +6,7 @@ import (
commonDB "Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/utils"
"github.com/garyburd/redigo/redis"
"github.com/golang-jwt/jwt/v4"
"time"
)
@@ -43,6 +44,21 @@ func CreateToken(userID string, platformID int32) (string, int64, error) {
if err != nil {
return "", 0, err
}
//remove Invalid token
m, err := commonDB.DB.GetTokenMapByUidPid(userID, constant.PlatformIDToName(platformID))
if err != nil && err != redis.ErrNil {
return "", 0, err
}
var deleteTokenKey []string
for k, v := range m {
if v != constant.NormalToken {
deleteTokenKey = append(deleteTokenKey, k)
}
}
err = commonDB.DB.DeleteTokenByUidPid(userID, platformID, deleteTokenKey)
if err != nil {
return "", 0, err
}
err = commonDB.DB.AddTokenFlag(userID, platformID, tokenString, constant.NormalToken)
if err != nil {
return "", 0, err