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

Sync Logout across tabs #5190

Merged
merged 4 commits into from
Sep 13, 2021
Merged

Sync Logout across tabs #5190

merged 4 commits into from
Sep 13, 2021

Conversation

parasharrajat
Copy link
Member

@parasharrajat parasharrajat commented Sep 10, 2021

Details

#4971 (comment)

Fixed Issues

$ #4971

Tests | QA Steps

  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, the user should be automatically signed out.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

logout-d.mp4

Mobile Web

Desktop

iOS

Android

@parasharrajat parasharrajat requested a review from a team as a code owner September 10, 2021 16:34
@MelvinBot MelvinBot requested review from marcaaron and removed request for a team September 10, 2021 16:34
@@ -47,6 +47,10 @@ function redirectToSignIn(errorMessage) {
if (activeClients && activeClients.length > 0) {
Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients);
}

// We must set the authToken to null so that signOut action is triggered across other clients
// https://github.com/Expensify/App/issues/4971#issuecomment-916101493
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 wonder if we need the link to the issue. If someone is curious about this we can use git blame and hopefully learn why some decision was made.


// We must set the authToken to null so that signOut action is triggered across other clients
// https://github.com/Expensify/App/issues/4971#issuecomment-916101493
Onyx.set(ONYXKEYS.SESSION, {authToken: null});
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this going to overwrite the error message above? Since we are calling Onyx.set() with ONYXKEYS.SESSION if we have an errorMessage and then again here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah. I didn't notice. I think I can merge both together.

if (errorMessage) {
session.error = errorMessage;
}
Onyx.merge(ONYXKEYS.SESSION, session);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not keep Onyx.set here, now that we combined error and authToken keys into one object?

Copy link
Member Author

@parasharrajat parasharrajat Sep 13, 2021

Choose a reason for hiding this comment

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

After, Onyx.clear, Onyx is initialized with the initial data https://github.com/Expensify/react-native-onyx/blob/6eadd7f73fca87e6551e43607ec78f645e17ef50/lib/Onyx.js#L618.

set here, was replacing that. So I used merge

[ONYXKEYS.SESSION]: {loading: false, shouldShowComposeInput: true},

Copy link
Contributor

Choose a reason for hiding this comment

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

Aah nice, thanks for pointing that out! 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

NAB, it might be worth adding a brief comment here explaining why we're not using a set(). That explanation makes sense to me, but someone might have the innocent idea to change this from a merge() to a set() and break the intended behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment added.

@Beamanator Beamanator self-requested a review September 13, 2021 12:33
Beamanator
Beamanator previously approved these changes Sep 13, 2021
Copy link
Contributor

@Beamanator Beamanator left a comment

Choose a reason for hiding this comment

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

Looking good 👍 All you @marcaaron

marcaaron
marcaaron previously approved these changes Sep 13, 2021
@parasharrajat parasharrajat dismissed stale reviews from marcaaron and Beamanator via fc4323c September 13, 2021 17:25
@marcaaron marcaaron merged commit db960af into Expensify:main Sep 13, 2021
@OSBotify
Copy link
Contributor

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

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

@isagoico
Copy link

We found this issue #5245 while testing this. Not sure if it fails the PR or not (I would say no, but I wanted to double check) @parasharrajat @marcaaron @Beamanator

@parasharrajat
Copy link
Member Author

@Beamanator Please let us know your opinion here. I think it is fine until the user is not able to use the other tab to do some actions.

@aldo-expensify
Copy link
Contributor

I think it may be happening because the other tab is not logged out in Safari, see #5245 (comment)

@isagoico
Copy link

Yep, it is because of that. That's why I think this PR is still a pass. Also, not 100% sure if the issue is "real" since it's like a refresh to show the correct user and load the new information.

@aldo-expensify
Copy link
Contributor

Yep, it is because of that. That's why I think this PR is still a pass. Also, not 100% sure if the issue is "real" since it's like a refresh to show the correct user and load the new information.

Hmm, just did the same exercise again and now both tabs sync properly 🤷 . I just updated my macOS, I wonder if that updated Safari and now it works? 🤷 🤷 🤷 or maybe I was testing with a cached version of the newDot in Safari.

@Beamanator
Copy link
Contributor

I also tested in Safari today and it looks like this passed 👍

One small thing I noticed: The welcome message on the signin page is different on the 2 tabs:

Screen.Recording.2021-09-15.at.1.50.33.PM.mov

@isagoico
Copy link

Oh I think it's because in one tab you landed in the enter email page and in the other it was the enter password 🤔

@isagoico
Copy link

isagoico commented Sep 15, 2021

I just tested on my side and it was not reproducible, the sync was a LOT faster 🤔

Edit: I'm gonna check this PR off the list, please stop me if you disagree.

@parasharrajat
Copy link
Member Author

Thanks, guys for proactively testing it.

@botify
Copy link

botify commented Sep 15, 2021

This has been deployed to production and is now subject to a 7-day regression period.
If no regressions arise, payment will be issued on 2021-09-22. 🎊

@OSBotify
Copy link
Contributor

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

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

@parasharrajat parasharrajat deleted the synglogout branch November 20, 2023 13:07
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.

7 participants