From 06d26389d9c52c310bb8900109ba87758ade0660 Mon Sep 17 00:00:00 2001 From: Abram Date: Mon, 18 Dec 2023 12:51:12 +0100 Subject: [PATCH] Update - use uuid4 in environments that does not suppoer localStorage --- agenta-web/src/lib/helpers/utils.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/agenta-web/src/lib/helpers/utils.ts b/agenta-web/src/lib/helpers/utils.ts index 8cd7b9122b..2d6ca99dac 100644 --- a/agenta-web/src/lib/helpers/utils.ts +++ b/agenta-web/src/lib/helpers/utils.ts @@ -316,10 +316,14 @@ export const shortPoll = async ( } export const generateOrRetrieveDistinctId = (): string => { - let distinctId = localStorage.getItem("posthog_distinct_id") - if (!distinctId) { - distinctId = uuidv4() - localStorage.setItem("posthog_distinct_id", distinctId) + if (typeof localStorage !== "undefined") { + let distinctId = localStorage.getItem("posthog_distinct_id") + if (!distinctId) { + distinctId = uuidv4() + localStorage.setItem("posthog_distinct_id", distinctId) + } + return distinctId + } else { + return uuidv4() } - return distinctId }