Skip to content
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

fix: logout clear storage missing promise await #612

Merged
merged 1 commit into from Aug 23, 2022
Merged

Conversation

peterpeterparker
Copy link
Member

Description

The logout function does not await for the storage to be cleared before reloading the window. This can lead to an edge case race condition where the storage would partially cleared after logout while the window is reloaded.

Fixes # (issue)

NNS-dapp PR #1247

How Has This Been Tested?

Jest test in nns-dapp that failed:

it("agent-js should clear indexeddb auth info on logout", async () => {
      const idbStorage = new IdbStorage();
      await idbStorage.set("delegation", "value");

      const value = await idbStorage.get("delegation");
      expect(value).not.toBeNull();

      await logout({});

      const valueCleared = await idbStorage.get("delegation");
      expect(valueCleared).toBeNull(); // <--- value was still set
    });

Checklist:

@krpeacock krpeacock merged commit eab9f50 into main Aug 23, 2022
@krpeacock krpeacock deleted the fix/logout-storage branch August 23, 2022 15:47
peterpeterparker added a commit to dfinity/nns-dapp that referenced this pull request Aug 24, 2022
# Motivation

agent-js `v0.13.x` introduces a breaking change. It uses indexeddb instead of local storage to save the session delegation and identity.

Indexddb is awesome and it's the most convenient way to access these information from web workers which we are already using for the cron that checks the delegation and which we might use for more features in the future.

# ⚠️ Important Note ⚠️ 

- on logout, local storage is not going cleared anymore but idb instead
- we don't explicitly clear idb but defer the work to agent-js which do so
- instead of syncing the auth on local storage changes, the identity will be checked in the auth cron

#  Dependencies

fake-indexeddb (https://github.com/dumbmatter/fakeIndexedDB) has been added to mock idb for jest tests happening in the nodejs context

# PRs required

- [X] ic-js PR dfinity/ic-js#177
- [x] agent-js PR dfinity/agent-js#611
- [x] agent-js PR dfinity/agent-js#612

# Changes

- in web worker, read delegation from idb instead of localstorage to check the validity of the delegation
- in web worker, also check the auth is authenticated
- on logout, do not clear local storage
- mock idb for test with new dev dependency `fake-indexeddb`
- remove auth sync on local storage changes
- bump agent-js `v0.13.2`
- bump most recent nns-js, sns-js and utils-js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants