From 67b010df36c32c4f9d391614044aa3242d017b8a Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Thu, 14 Nov 2024 09:27:49 -0500 Subject: [PATCH] Fix posthog identify and clear on logout --- packages/keychain/src/hooks/connection.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/keychain/src/hooks/connection.ts b/packages/keychain/src/hooks/connection.ts index fe62d8a47..ad510f334 100644 --- a/packages/keychain/src/hooks/connection.ts +++ b/packages/keychain/src/hooks/connection.ts @@ -78,13 +78,18 @@ export function useConnectionValue() { }, [context, parent]); const setController = useCallback((controller?: Controller) => { - posthog.identify(controller.cartridge.username(), { - address: controller.address, - class: controller.cartridge.classHash, - chainId: controller.chainId, - appId: origin, - }); - posthog.group("company", origin); + if (controller && controller.cartridge) { + posthog.identify(controller.cartridge.username(), { + address: controller.address, + class: controller.cartridge.classHash, + chainId: controller.chainId, + appId: origin, + }); + + posthog.group("company", origin); + } else { + posthog.reset(); + } setControllerRaw(controller); setIsSignedUp();