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

fix: return a rejected promise when inner token is null or undefined #83

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

erezrokah
Copy link
Contributor

Related to decaporg/decap-cms#941, specifically decaporg/decap-cms#941 (comment)

When a call to _refreshToken inside the jwt methods fails, the inner token property is set to null here:

this.clearSession();

That can happen when the refresh token is no longer valid as specified here netlify/netlify-identity-widget#142 (comment)

Subsequence calls to jwt will fail when trying to access a null token, but won't return a rejected promise thus breaking catch clauses like these ones:

return this._request("/logout", { method: "POST" })

https://github.com/netlify/netlify-identity-widget/blob/c104dd18bb3b87d2a66936e15f064d5659259686/src/state/store.js#L146

since jwt is called on each _request that makes error handling very problematic once a refresh operation fails.

The fix is to return a rejected promise if the token is null or undefined

@erezrokah erezrokah added the type: bug code to address defects in shipped code label Jun 2, 2020
Copy link
Contributor

@ehmicky ehmicky left a comment

Choose a reason for hiding this comment

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

Looks good!

@erezrokah erezrokah merged commit 2ae4de5 into master Jun 4, 2020
@erezrokah erezrokah deleted the fix/reject_jwt_null_token branch June 4, 2020 14:28
erezrokah pushed a commit that referenced this pull request Jun 30, 2020
## [0.9.26](v0.9.25...v0.9.26) (2020-06-30)

### Bug Fixes

* **docs:** format readme file and add some missing arguments ([#110](#110)) ([738998e](738998e))
* return a rejected promise when inner token is null or undefined ([#83](#83)) ([2ae4de5](2ae4de5))
@erezrokah
Copy link
Contributor Author

🎉 This PR is included in version 0.9.26 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants