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

Cleanup Pusher subscriptions when signing out in another tab #5555

Merged
merged 9 commits into from
Sep 28, 2021

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented Sep 28, 2021

Details

When signing out in another tab we are not always unsubscribing from Pusher. This is because the authToken gets removed, but none of the logic that runs in redirectToSignIn() runs on additional tabs. Additionally, the Onyx cache does not get cleared in other tabs although storage does (because it is shared). This PR solves these two issues by:

  • moving unsubscribe logic into the lifecycle of AuthScreens component which will unmount whenever the authToken is unset
  • call Onyx.clear() on all tabs (for the session) and not just the one where we sign out

Fixed Issues

$ #5034
$ https://github.com/Expensify/Expensify/issues/177689

Tests / QA Steps

  1. Sign in as User A in one tab
  2. Open an additional tab
  3. Send a message from User B to User A from an entirely different browser session (e.g. incognito tab)
  4. Log out of User A in the second tab opened
  5. Log in as User C in that same tab
  6. Send a message as User B to User A
  7. Verify that User C is not able to access the chat between User B and User A and that no chats that are not supposed to exists show up.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Mobile Web

Desktop

iOS

Android

@marcaaron marcaaron self-assigned this Sep 28, 2021
@marcaaron marcaaron marked this pull request as ready for review September 28, 2021 16:40
@marcaaron marcaaron requested a review from a team as a code owner September 28, 2021 16:40
@MelvinBot MelvinBot requested review from aldo-expensify and removed request for a team September 28, 2021 16:40
@aldo-expensify
Copy link
Contributor

I'll review this after lunch!

@@ -249,7 +250,7 @@ class AuthScreens extends React.Component {
if (this.unsubscribeGroupShortcut) {
this.unsubscribeGroupShortcut();
}
NetworkConnection.stopListeningForReconnect();
cleanupSession();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: I was wondering why do we do this here instead of in clearStorageAndRedirect. I feels like the clean up logic is spread and it could be more centralized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, mainly because we are setting up the subscriptions in AuthScreens componentDidMount() here:

componentDidMount() {
NetworkConnection.listenForReconnect();
PusherConnectionManager.init();

so I thought it made more sense to tear them down in componentWillUnmount().

We definitely could do it in clearStorageAndRedirect() but I think making the "cleanup" stuff a side effect of losing the authToken is OK because we set up a lot of logic in componentDidMount() that could also be triggered by the presence of the authToken.

Basically the assumption is that AuthScreens mounted = we have authToken and AuthScreen unmount = we lost the authToken.

But yeah I wouldn't mind cleaning this up eventually or doing something differently if it becomes complicated enough to where people are thoroughly confused about how it works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, mainly because we are setting up the subscriptions in AuthScreens componentDidMount() here:

Ohh that makes sense, I only looked at the code in componentWillUnmount

But yeah I wouldn't mind cleaning this up eventually or doing something differently if it becomes complicated enough to where people are thoroughly confused about how it works.

Agreed, I think it is good for now like it is, there is a good enough reason to keep it there.

Copy link
Contributor

@aldo-expensify aldo-expensify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it in web, it works 🎉

Left a NAB.

@aldo-expensify aldo-expensify merged commit d54f307 into main Sep 28, 2021
@aldo-expensify aldo-expensify deleted the marcaaron-cleanUpPusherSubscriptions branch September 28, 2021 23:01
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @aldo-expensify in version: 1.1.3-2 🚀

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

@OSBotify
Copy link
Contributor

OSBotify commented Oct 4, 2021

🚀 Deployed to production by @chiragsalian in version: 1.1.4-0 🚀

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

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

3 participants