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

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

Closed
isagoico opened this issue Sep 1, 2021 · 17 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Engineering External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@isagoico
Copy link

isagoico commented Sep 1, 2021

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

Grabando.211.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)

@MelvinBot
Copy link

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

@MelvinBot
Copy link

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

@MelvinBot
Copy link

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

@Hanaffi
Copy link

Hanaffi commented Sep 8, 2021

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.

@Beamanator
Copy link
Contributor

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 :)

@MelvinBot MelvinBot removed the Overdue label Sep 9, 2021
@parasharrajat
Copy link
Member

parasharrajat commented Sep 9, 2021

This issue is caused but calling Onyx.clear instead of resetting the key.
Recently a change was made 72bf6c0 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.

window.addEventListener('storage', (e) => {

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

 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.

@Beamanator
Copy link
Contributor

@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 👍

@parasharrajat
Copy link
Member

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.

@kidroca
Copy link
Contributor

kidroca commented Sep 10, 2021

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

@Beamanator Beamanator self-assigned this Sep 10, 2021
@Beamanator Beamanator added the External Added to denote the issue can be worked on by a contributor label Sep 10, 2021
@MelvinBot
Copy link

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

@Beamanator
Copy link
Contributor

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 💯

@puneetlath
Copy link
Contributor

Invited @parasharrajat to the Upwork job.

@MelvinBot MelvinBot added Help Wanted Apply this label when an issue is open to proposals by contributors and removed Daily KSv2 labels Sep 10, 2021
@puneetlath puneetlath removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Sep 10, 2021
@botify
Copy link

botify commented Sep 13, 2021

🚀 Deployed to staging by @marcaaron in version: 1.0.97-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@botify botify added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Sep 15, 2021
@botify botify changed the title After sign out, user should be signed out of all tabs [HOLD for payment 2021-09-22] After sign out, user should be signed out of all tabs Sep 15, 2021
@botify
Copy link

botify commented Sep 15, 2021

🚀 Deployed to production by @francoisl in version: 1.0.98-1 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@botify botify added Weekly KSv2 and removed Weekly KSv2 labels Sep 20, 2021
@botify
Copy link

botify commented Sep 20, 2021

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

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

@botify botify changed the title [HOLD for payment 2021-09-22] After sign out, user should be signed out of all tabs [HOLD for payment 2021-09-27] [HOLD for payment 2021-09-22] After sign out, user should be signed out of all tabs Sep 20, 2021
@mountiny
Copy link
Contributor

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

@mountiny mountiny changed the title [HOLD for payment 2021-09-27] [HOLD for payment 2021-09-22] After sign out, user should be signed out of all tabs [HOLD for payment 2021-09-22] After sign out, user should be signed out of all tabs Sep 20, 2021
@puneetlath
Copy link
Contributor

Paid!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Engineering External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
None yet
Development

No branches or pull requests