App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2021-09-22] After sign out, user should be signed out of all tabs

Open isagoico opened this issue 5 years ago β€’ 17 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Sign in to New Expensify in one tab (A), open a second tab (B) with New Expensify (you should be signed in automatically)
  2. In tab A, sign out then sign in with a new account
  3. In tab B, navigate through several conversations.

Expected Result:

User should be signed out from all tabs.

Actual Result:

User is able to navigate through conversations after logging out from Tab A. An error can be seen in JS console.

Workaround:

User has to refresh the page to see correct conversations.

Platform:

Where is this issue occurring?

  • Web
  • Mobile Web

Version Number: 1.0.90-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

image

https://user-images.githubusercontent.com/44479856/131591449-9277223b-06f9-469e-ad3d-d584480addf8.mp4

Expensify/Expensify Issue URL:

View all open jobs on GitHub


From @Beamanator https://expensify.slack.com/archives/C01GTK53T8Q/p1630410901192800

BUG: Seeing combined chats from previously signed-in user in tab that stayed open through signout/signin. Flow: Sign in to New Expensify in one tab (A), open a second tab (B) with New Expensify (you should be signed in automatically) In tab A, sign out then sign in with a new account In tab B, I’m seeing existing chats from the new account (good) & the previously signed in account (bad)

isagoico avatar Sep 01 '21 00:09 isagoico

Triggered auto assignment to @cead22 (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Sep 01 '21 00:09 MelvinBot

Triggered auto assignment to @Gonals (Demolition), see https://stackoverflow.com/c/expensify/questions/8099 for more details.

MelvinBot avatar Sep 02 '21 17:09 MelvinBot

Huh... This is 4 days overdue. Who can take care of this?

MelvinBot avatar Sep 07 '21 19:09 MelvinBot

Proposal

It would be great to pass signals between tabs. There are a couple of methods, I want to tell you about using localStorage. You can attach a listener to a storage event (fired when storage item is changed) and send a logout-event signal.

localStorage.setItem('logout-event', 'logout' + Math.random());

Every other tab will get it with a listener.

window.addEventListener('storage', function(event){
    if (event.key == 'logout-event') { 
        // ..
    }
});

We could also make an ajax request to your server every 3 seconds is useful just in case some of the users use very old browsers.

Hanaffi avatar Sep 08 '21 11:09 Hanaffi

Hello @Hanaffi , thanks for your proposal! Have you looked into our code base much? Specifically how react-native-onyx works? I ask because this library ends up storing & retrieving data from localStorage :)

Beamanator avatar Sep 09 '21 12:09 Beamanator

This issue is caused but calling Onyx.clear instead of resetting the key. Recently a change was made https://github.com/Expensify/App/commit/72bf6c0c369324a73b58a33339598db42a35880a to fix another issue. But calling Onyx.clear ==> localstorage.clear does not pass any key to the storage event which is used to sync the tabs. https://github.com/Expensify/App/blob/77dea941898c2ec25a62fc46b4f41235a9b3479f/src/libs/listenToStorageEvents/index.js#L8

So change is never triggered across tabs for Onyx.clear. For this reason we used to reset the session key before. Now no update is pass to other tabs for the session key thus logout is not synced across tabs.

But this change is necessary as explained in the commit, I think the fix would be rather simple. we just need to reset the session explicitly with Onyx clear.

@Beamanator First, no one is assigned to this issue. Second, to fix this issue https://github.com/Expensify/App/blob/72bf6c0c369324a73b58a33339598db42a35880a/src/libs/actions/SignInRedirect.js#L49

 Onyx.clear()
        .then(() => {
            if (preferredLocale) {
                Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, preferredLocale);
            }
            if (errorMessage) {
                Onyx.set(ONYXKEYS.SESSION, {error: errorMessage});
            }
            if (activeClients && activeClients.length > 0) {
                Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients);
            }
      // Explicitly reset the session so that logout could be synced across tabs.
            Onyx.set(ONYXKEYS.SESSION, {authToken: null});
        });

we can't revert the above-mentioned commit as it fixes another issue and Kidroca has explained why it is needed.

parasharrajat avatar Sep 09 '21 13:09 parasharrajat

@parasharrajat Thanks very much for your investigation! I noted this in the issue @kidroca 's PR fixed, let's collaborate and make sure this is the best solution πŸ‘

Beamanator avatar Sep 10 '21 10:09 Beamanator

Sure, I think the solution I proposed is easiest. We use to do previously but in reverse order. I mean first session used to reset and then we clear it. But that had many side-effects. So We just need to tell other tabs that session key is changed and I set authToken to null as It is implicitly null or undefined after logout.

Hmm, happy to help.

parasharrajat avatar Sep 10 '21 10:09 parasharrajat

Confirming the discussion and the proposed solution.

No storage event is raised and so other tabs are unaware of the change

Thanks for the investigation and for pointing that out in the new code comment

Onyx.clear notifies only the current tab subscribers through keysChanged

kidroca avatar Sep 10 '21 13:09 kidroca

Triggered auto assignment to @puneetlath (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Sep 10 '21 14:09 MelvinBot

Thanks for confirming, @kidroca πŸ‘

@parasharrajat thanks for bearing with me, I'm assigning this job to you - please submit a PR when you have a chance πŸ’―

Beamanator avatar Sep 10 '21 14:09 Beamanator

Invited @parasharrajat to the Upwork job.

puneetlath avatar Sep 10 '21 17:09 puneetlath

πŸš€ Deployed to staging by @marcaaron in version: 1.0.97-3 πŸš€

platform result
πŸ€– android πŸ€– success βœ…
πŸ–₯ desktop πŸ–₯ success βœ…
🍎 iOS 🍎 success βœ…
πŸ•Έ web πŸ•Έ success βœ…

botify avatar Sep 13 '21 20:09 botify

πŸš€ Deployed to production by @francoisl in version: 1.0.98-1 πŸš€

platform result
πŸ€– android πŸ€– success βœ…
πŸ–₯ desktop πŸ–₯ success βœ…
🍎 iOS 🍎 success βœ…
πŸ•Έ web πŸ•Έ success βœ…

botify avatar Sep 15 '21 20:09 botify

The solution for this issue has been :rocket: deployed to production :rocket: in version 1.0.98-1 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:

  • https://github.com/Expensify/App/pulls/5190\n

If no regressions arise, payment will be issued on 2021-09-27. :confetti_ball:

botify avatar Sep 20 '21 20:09 botify

This is a bug, caused by today's deploy and some weird GH API behaviour. Updated the title back to what it was πŸ™‡

mountiny avatar Sep 20 '21 22:09 mountiny

Paid!

puneetlath avatar Sep 22 '21 14:09 puneetlath