Skip to content

fix: always remove guestIdentityId from keyValueStorage on client-side #14437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('DefaultIdentityIdStore', () => {

afterEach(() => {
mockKeyValueStorage.setItem.mockClear();
mockKeyValueStorage.getItem.mockClear();
mockKeyValueStorage.getItem.mockReset();
mockKeyValueStorage.removeItem.mockClear();
mockKeyValueStorage.clear.mockClear();
});
Expand All @@ -73,6 +73,7 @@ describe('DefaultIdentityIdStore', () => {
});

it('should store primary identityId in keyValueStorage', async () => {
mockKeyValueStorage.getItem.mockResolvedValue(validGuestIdentityId.id);
defaultIdStore.storeIdentityId(validPrimaryIdentityId);
expect(mockKeyValueStorage.removeItem).toHaveBeenCalledWith(
validAuthKey.identityId,
Expand Down Expand Up @@ -114,6 +115,7 @@ describe('DefaultIdentityIdStore', () => {
});

it('should not call keyValueStorage.removeItem when there is no guest identityId to clear', async () => {
mockKeyValueStorage.getItem.mockReturnValue(null);
const refreshIdentityIdStore = new DefaultIdentityIdStore(
mockKeyValueStorage,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export class DefaultIdentityIdStore implements IdentityIdStore {
} else {
this._primaryIdentityId = identity.id;
// Clear locally stored guest id
if (this._hasGuestIdentityId) {
this.keyValueStorage.removeItem(this._authKeys.identityId);
// On the server-side we use the _hasGuestIdentityId flag to avoid caching issues
const serverside = typeof window === 'undefined';
if (this._hasGuestIdentityId || !serverside) {
if (this.keyValueStorage.getItem(this._authKeys.identityId) !== null) {
this.keyValueStorage.removeItem(this._authKeys.identityId);
}
this._hasGuestIdentityId = false;
}
}
Expand Down
Loading