devicemngmt/action_get_user_id.go

37 lines
660 B
Go
Raw Permalink Normal View History

2021-11-05 10:36:30 +00:00
package devicemngmt
import (
"context"
2022-10-10 08:50:17 +00:00
"git.selly.red/Selly-Modules/logger"
2021-11-05 10:36:30 +00:00
"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{
2021-11-05 10:36:30 +00:00
"authToken": authToken,
"err": err.Error(),
})
return
}
2021-11-22 08:14:36 +00:00
userID = device.UserID.Hex()
2021-11-05 10:36:30 +00:00
return
}