fix(auth): namespace storage key to prevent cross-instance collision #1110
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.
This PR fixes a critical authentication issue where multiple EmbeddedChat instances running on the same domain were overwriting each other’s login sessions.
The problem was caused by a hardcoded
localStoragekey (ec_token) used by all instances. As a result, logging into one EmbeddedChat instance would invalidate the session of another.This fix introduces namespaced storage keys, ensuring that each EmbeddedChat instance maintains an isolated authentication session based on its configuration.
Closes #1105
Solution
Token storage is now scoped per instance using a dynamic storage key.
Each EmbeddedChat instance generates its own unique key using:
This guarantees session isolation across different servers or rooms.
Changes Made
1.
auth.jsgetTokenStorageto accept a dynamic storage key instead of using a hardcoded value.2.
EmbeddedChat.jshostandroomId.getTokenStorageinuseMemoto prevent unnecessary re-renders, since it returns new function references on each call.Performance Consideration
useMemois used to memoize the token storage handlers.