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

Add 'lock' to prevent getTokenSilently to be invoked in parallel #238

Merged
merged 3 commits into from
Oct 23, 2019

Conversation

luisrudge
Copy link
Contributor

Description

Today, the getTokenSilently method behaves like this:

  • create an iframe
  • attach a listener to the window to receive messages from the iframe
  • when the message from the iframe arrives, it removes the listener and the iframe from the DOM

The problem we have today is that if you call the method concurrently, we can hit a race condition where, by having two iframes at the same time, the order of the response is mixed and by the time you try to remove the iframe, it’s already gone and it throws an error (#109).

This PR implements a 'lock' the current instance of the Auth0Client in all instances of your app (from the same browser) until the getTokenSilently call is finished. This enables us to always* execute the method once at a time.

  • This is not a real lock. It's a best effort lock due to platform limitations. In mobile or when a tab is 'sleeping', it might be the case that the lock is not made correctly for that particular tab, that's when proper error handling (something we'll work on) will help.

References

fix #109

Testing

  • This change adds test coverage for new/changed/fixed functionality

@luisrudge luisrudge requested a review from a team October 21, 2019 17:55
@joshcanhelp joshcanhelp requested review from joshcanhelp and removed request for a team October 21, 2019 17:58
Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

LGTM!

What's the package size increase?

@@ -1,3 +1,5 @@
import Lock from 'browser-tabs-lock';
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you mean:

import Lock from 'auth0-lock';

😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

geez. can you imagine that? 😝

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.

Unable to call getTokenSilently concurrently
2 participants