Enrich onRedirectCallback method with User object (#400) #401
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Enhance the
onRedirectCallback
prop in theAuth0Provider
to expose the user, in this case, to conditionally redirect users.For example:
Say a user is marked as a VIP in Auth0 as a means of enhancing that user's experience in the app. When the user logs in or creates an account as a VIP, they're redirected to a particular page and presented with special content as a VIP.
The implementation above allows developers to tailor the user's experience based on context from both the
appState
and any special properties attached to theuser
object after authentication with Auth0. Effectively creating a shorter journey to get the user where they need to be.Without this implementation, where the user should be redirected to would be delegated to logic further down the component tree and would not have access to context from
appState
. This would require a different means of storing context about the user's authentication journey, likely inlocalStorage
, before the user begins authentication with Auth0. That would look something like:To my knowledge, this would be a non-breaking change with a minimal API change that only surfaces the user object to the
onRedirectCallback
method's second function argument.References
Resolves #400
Testing
Authentication behavior can be tested by running the demo application included with this package. You could test the new implementation by setting conditional logic based on the
user
object inside a customonRedirectCallback
method.My environment consists of:
Checklist