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

Changes to logout and cache synchronicity #758

Merged
merged 5 commits into from
Jul 7, 2021
Merged

Conversation

stevehobbsdev
Copy link
Contributor

@stevehobbsdev stevehobbsdev commented Jul 7, 2021

Description

This PR makes the following changes around logout and caching:

  • logout can now optionally return a Promise. This is currently the case when a custom cache implementation is specified using the cache option
  • If no custom cache implementation is used, logout acts synchronously and does not return a promise
  • ICache methods (get, set, remove, allKeys) can now optionally return a promise or a static value, and is handled seamlessly
  • docs updated
  • internal caches changed to return static values, instead of wrapping them in Promise.resolve

The motivation was for SDKs like auth0-angular and auth0-react who update their internal state reactively can now rely on logout being synchronous by default, and update their state accordingly.

Note that none of this should be a breaking change for consumers:

  • If anyone already has a custom cache and are returning a Promise, that will continue to work
  • Up until now, logout never returned a value so there was nothing to handle

Testing

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

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@stevehobbsdev stevehobbsdev added CH: Fixed PR is fixing a bug review:medium Medium review labels Jul 7, 2021
@stevehobbsdev stevehobbsdev requested a review from a team as a code owner July 7, 2021 11:44
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Jul 7, 2021

This pull request introduces 1 alert when merging c31598a into ecafb37 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

window.location.assign(url);
};

if (this.options.cache) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should do:

const maybePromise = this.cacheManager.clear();
if (typeof maybePromise?.then === 'function') {
  return maybePromise.then(postCacheClear)
}
postCacheClear();

Then the advice would be If you provide an async cache ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds reasonable!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Diving into this, cacheManager.clear will always return a Promise; are you also suggesting removing cacheManager.clearSync?

Copy link
Contributor

Choose a reason for hiding this comment

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

D'oh - no sorry, I forgot about clear/clearSync ignore me

@stevehobbsdev stevehobbsdev merged commit e84aecb into master Jul 7, 2021
@stevehobbsdev stevehobbsdev deleted the fix/async-logout branch July 7, 2021 15:36
@stevehobbsdev stevehobbsdev added this to the v1.16.1 milestone Jul 7, 2021
@stevehobbsdev stevehobbsdev mentioned this pull request Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Fixed PR is fixing a bug review:medium Medium review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants