patch getDistinctId

This commit is contained in:
Maidul Islam
2023-12-13 19:12:02 -05:00
parent 7f7f11c970
commit 460ebf3296
+7 -6
View File
@@ -8,12 +8,12 @@ import {
getTelemetryEnabled, getTelemetryEnabled,
} from "../config"; } from "../config";
import { import {
Identity,
ServiceTokenData, ServiceTokenData,
User, User
} from "../models"; } from "../models";
import { import {
AccountNotFoundError, AccountNotFoundError,
BadRequestError,
} from "../utils/errors"; } from "../utils/errors";
class Telemetry { class Telemetry {
@@ -52,6 +52,7 @@ class Telemetry {
}: { }: {
authData: AuthData; authData: AuthData;
}) => { }) => {
let distinctId = ""; let distinctId = "";
if (authData.authPayload instanceof User) { if (authData.authPayload instanceof User) {
distinctId = authData.authPayload.email; distinctId = authData.authPayload.email;
@@ -61,12 +62,12 @@ class Telemetry {
if (!user) throw AccountNotFoundError(); if (!user) throw AccountNotFoundError();
distinctId = user.email; distinctId = user.email;
} }
} else if (authData.authPayload instanceof Identity) {
distinctId = `identity-${authData.authPayload._id.toString()}`
} else {
distinctId = "unknown-auth-data"
} }
if (distinctId === "") throw BadRequestError({
message: "Failed to obtain distinct id for logging telemetry",
});
return distinctId; return distinctId;
} }
} }