add an async getUser
function to Auth0ContextInterface
#816
+50
−0
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
the
Auth0ContextInterface
provides auth state and a bunch of async methods for updating that auth state. theuser
, however, is only populated in state as a side effect of other methods (namelygetAccessTokenSilently
,getAccessTokenWithPopup
, andhandleRedirectCallback
) which means there is no way for a client to guarantee they have access when they first mount the hook. the standard way to deal with this is with an effect -- mount the hook, callgetAccessTokenSilently
or something, and rerender when the user is fetched. however, this isnt always possible, for instance tanstack router'sbeforeLoad
method is a place where it would be really useful toawait
a user (to determine if they have access to this specific route). as of now, this library provides no way to do this, so i added this quick wrapper around theclient.getUser
method, for use in contexts where we cant rely on rerenders.Testing
i relied on unit tests to test this, but theyre not particularly inspired -- given that this function just wraps
client.getUser
there really isnt much to test here.Checklist
getAccessTokenWithPopup