From d8223cd49cdf933a0607f66670ba7225b84f149c Mon Sep 17 00:00:00 2001 From: Patryk Kalinowski Date: Fri, 29 Nov 2024 21:51:40 +0100 Subject: [PATCH] remove timeDriftKey from sessionStorage on user logout --- packages/waas/src/auth.ts | 1 + packages/waas/src/intents/base.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/waas/src/auth.ts b/packages/waas/src/auth.ts index 515d73b96..b10ac3873 100644 --- a/packages/waas/src/auth.ts +++ b/packages/waas/src/auth.ts @@ -610,6 +610,7 @@ export class SequenceWaaS { session.clear() await this.waas.completeSignOut() await this.deviceName.set(undefined) + updateTimeDrift(undefined) } } diff --git a/packages/waas/src/intents/base.ts b/packages/waas/src/intents/base.ts index 2fe8f1778..0f9caecbf 100644 --- a/packages/waas/src/intents/base.ts +++ b/packages/waas/src/intents/base.ts @@ -32,7 +32,15 @@ export function getTimeDrift() { return timeDrift } -export function updateTimeDrift(serverTime: Date) { +export function updateTimeDrift(serverTime?: Date) { + if (!serverTime) { + timeDrift = undefined + if (isSessionStorageAvailable()) { + window.sessionStorage.removeItem(timeDriftKey) + } + return + } + timeDrift = (getLocalTime() - serverTime.getTime()) / 1000 if (isSessionStorageAvailable()) { window.sessionStorage.setItem(timeDriftKey, timeDrift.toString(10))