devicemngmt/action_get_user_id.go

38 lines
697 B
Go
Raw Normal View History

2021-11-05 10:36:30 +00:00
package devicemngmt
import (
"context"
"github.com/Selly-Modules/logger"
"go.mongodb.org/mongo-driver/bson"
)
// GetUserIDByAuthToken ...
func (s Service) GetUserIDByAuthToken(authToken string) (userID string) {
var (
ctx = context.Background()
col = s.getDeviceCollection()
device = Device{}
cond = bson.M{
"authToken": authToken,
}
)
2021-11-26 10:24:14 +00:00
if authToken == "" {
return
}
2021-11-05 10:36:30 +00:00
// Find
if err := col.FindOne(ctx, cond).Decode(&device); err != nil {
2021-11-10 10:08:39 +00:00
logger.Error("devicemngmt - getUserIDByAuthToken", logger.LogData{
2022-10-05 10:23:29 +00:00
Source: "devicemngmt.GetUserIDByAuthToken",
Message: err.Error(),
Data: authToken,
2021-11-05 10:36:30 +00:00
})
return
}
2021-11-22 08:14:36 +00:00
userID = device.UserID.Hex()
2021-11-05 10:36:30 +00:00
return
}