Skip to content

Commit

Permalink
profile: prevent undefined identifier on identify
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-roland committed Sep 6, 2024
1 parent 8ce91fd commit 3acf794
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/modules/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export class ProfileModule implements BatchSDK.ProfileModule {
}

identify(identifier: string | null): void {
if (typeof identifier === 'undefined') {
writeBatchLog(
false,
"BatchProfile - Identifier cannot be undefined, please use explicit null if you want to logout. Aborting."
);
return;
}
sendToBridge(null, Profile.Identify, [{ custom_user_id: identifier }]);
}

Expand All @@ -39,31 +46,31 @@ export class ProfileModule implements BatchSDK.ProfileModule {
if (typeof location !== "object") {
writeBatchLog(
false,
"BatchUser - Invalid trackLocation argument. Skipping."
"BatchProfile - Invalid trackLocation argument. Skipping."
);
return;
}

if (typeof location.latitude !== "number" || isNaN(location.latitude)) {
writeBatchLog(false, "BatchUser - Invalid latitude. Skipping.");
writeBatchLog(false, "BatchProfile - Invalid latitude. Skipping.");
return;
}

if (typeof location.longitude !== "number" || isNaN(location.longitude)) {
writeBatchLog(false, "BatchUser - Invalid longitude. Skipping.");
writeBatchLog(false, "BatchProfile - Invalid longitude. Skipping.");
return;
}

if (
location.precision &&
(typeof location.precision !== "number" || isNaN(location.precision))
) {
writeBatchLog(false, "BatchUser - Invalid precision. Skipping.");
writeBatchLog(false, "BatchProfile - Invalid precision. Skipping.");
return;
}

if (location.date && !(location.date instanceof Date)) {
writeBatchLog(false, "BatchUser - Invalid date. Skipping.");
writeBatchLog(false, "BatchProfile - Invalid date. Skipping.");
return;
}

Expand Down

0 comments on commit 3acf794

Please sign in to comment.