Repository navigation
fix: namespace auth token storage key to prevent cross-instance sessi… - #1405
Open
swarnendusahu10-dotcom wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1105
When multiple EmbeddedChat instances (e.g. Sales Bot and Support Bot, or multi-tenant widgets) co-exist on the same domain, logging into one instance previously overwrote the authentication session of the other because the
localStoragekey was hardcoded to'ec_token'inpackages/react/src/lib/auth.js.This pull request introduces host-scoped namespaced token storage keys with an opt-in
tokenStorageKeyprop override and automatic backward-compatible session migration.Key Changes
Dynamic Namespaced Storage Keys (
packages/react/src/lib/auth.js):getTokenStorage(secure, key)and local storage helpers to accept a configurable storage key.getTokenLocalStoragefalls back to and migrates any existing legacy'ec_token'session so existing users are never logged out upon upgrading.Host-Scoped Resolution & Memoization (
packages/react/src/views/EmbeddedChat.js):ec_token_${normalizedHost}, ensuring different servers maintain completely independent sessions.roomId), ensuring that switching channels within the same chat instance does not log the user out.tokenStorageKeyprop withPropTypescoverage for integrators needing custom instance isolation on the same host.getTokenStorage(secure, storageKey)inuseMemoto eliminate unnecessary function recreations and prevent redundantRCInstancere-renders.Verification
https://sales.example.com) does not overwrite Instance B (https://support.example.com).'ec_token'migrate seamlessly without user intervention.npx prettier --check).npm run build(dist/cjsanddist/esmgenerated without errors).