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

Logout event for child apps #27

Open
maxceem opened this issue Jun 30, 2021 · 0 comments
Open

Logout event for child apps #27

maxceem opened this issue Jun 30, 2021 · 0 comments

Comments

@maxceem
Copy link
Contributor

maxceem commented Jun 30, 2021

Background

It could happen that we logout in the Navbar, and this would be reflected in the Navbar topbar (we would see login button), but other micro apps would not know about this event, unless they directly call getAuthUserTokens again.

In particular, we have this issue in TaaS Admin App topcoder-platform/micro-frontends-taas-admin-app#52

How to reproduce

  1. Login https://platform.topcoder-dev.com/taas-admin/work-periods
  2. Open one more tab with https://platform.topcoder-dev.com/taas-admin/work-periods and Logout
  3. Switch to the first tab where it is shown as logged-in.

    Wait until the current token expires. At that moment Navbar would try to refresh the token, but as we are already logged-out, it could not refresh the token and would update the status of Navbar as logged-out: use would disappear and login button would be shown.
  4. At the same time child miroapp would not know that user is logged-out now as there is no event about this. And if at this moment we would try to make any action inside the child app we would get an error like this Getting "No token provided" error if the page is not used for a certain period of time. micro-frontends-taas-admin-app#52

Solution

There are several ways to solve this. But it feels that the most consistent and robust way if Navbar would provide some event when a user is logged-out.

For example, it could export a method like subscribeToLogout(callback) so we could subscribe to the event of logout, and the callback should be invoked by the Navbar when user is logged out. And method unsubscribeFromLogout(callback).

Or it could be implemented a more general way by having 2 exported method in Navbar:

  • subscribe(evenName, callback) - subscribe to some event with name evenName
  • unsubscribe(eventName, callback) - unsubscribe to some event with name eventName and callback

This solution has one downside. The child app would have to always manually unsubscribe from all the events it subscribed to avoid memory leaks. So it would be better if we implement some automation logic that would unsubscribe child apps from all the events it subscribed to when the child app is unmounted. Though I'm not sure if it could lead to some edge cases or downsides.

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

No branches or pull requests

1 participant