aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

Make signedIn and signedOut event cross-tab #12820

Open AllanZhengYP opened 8 months ago

AllanZhengYP commented 8 months ago

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

Authentication

Is this related to another service?

No response

Describe the feature you'd like to request

Currently the Hub event signedIn and signedOut is only sent to the current browser tab/window. Hence the useAuthenticator hook does not change session state from the sign-in or sign-out action from other tab.

I expect the following to work:

  1. Open tab 1 of example.com and render unauthenticated scene.
  2. Open tab 2 of example.com/sign-in and completes sign-in flow
  3. Both tabs rerender the authenticated scene automatically.

Describe the solution you'd like

The Hub listener can opt to listen to cross tab events:

Hub.listen('auth', callback, { fromCrossTab: true });

Now you are listening to other tabs.

Under the hood it can listen to the cookie/local storage events and looking for user session changes.

Describe alternatives you've considered

Right now users have to refresh to render the effects from the signedIn and signedOut events from other tabs.

Additional context

No response

Is this something that you'd be interested in working on?

cwomack commented 8 months ago

Thanks for opening this @AllanZhengYP. Labeling this as a feature request and this behavior is consistent in both v5 and v6. Anyone who sees this/experiences this, feel free to upvote this issue and provide more context!

wasib-sureify commented 1 month ago

I am facing the same issue. I would like for this support to be added to the Hub listener.