Skip to content

fix(WithAuth): options.authRequired can default to undefined#9

Open
chrislambe wants to merge 1 commit into
auth0-lab:mainfrom
chrislambe:fix-auth-required-reference
Open

fix(WithAuth): options.authRequired can default to undefined#9
chrislambe wants to merge 1 commit into
auth0-lab:mainfrom
chrislambe:fix-auth-required-reference

Conversation

@chrislambe
Copy link
Copy Markdown

The options.authRequired check in onRequest is causing unexpected behavior. The docs say that authRequired defaults to true. However the way WithAuth is written, if an empty options object or an options object with only debug is provided, authRequired defaults to undefined.

This wouldn't be a problem because the local authRequired is set to true if options.authRequired is nullish, but onRequest checks options.authRequired instead of authRequired. For me this was causing onAuthenticatedRequest not to fire even though my request was providing an access token.

This PR changes onRequest to use the local authRequired. It also sets the options default value to {} instead of { authRequired: true } in an effort to prevent similar bugs in the future. Setting { authRequired: true } as the default value for options can only lead to confusion since the logic inside WithAuth should be using the local authRequired anyways.

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.

1 participant