add an async getUser function to Auth0ContextInterface#816
add an async getUser function to Auth0ContextInterface#816MisterSquishy wants to merge 2 commits intoauth0:mainfrom
getUser function to Auth0ContextInterface#816Conversation
|
Thanks for the PR and apologies for the delayed response. Are you still encountering this issue with TanStack Router beforeLoad hooks? If so, how did you work around it in the meantime? Understanding your current situation would help us prioritize this properly. |
|
Hey @yogeshchoudhary147 - the only workaround is to use a tool like patch-package to patch this functionality into auth0. This remains a problem for anyone who wants to access the current user in loaders using tanstack router which is a fairly common need. I would consider this high priority given:
|
|
Closing this in favour of #1041 which has now been merged. The |
Description
the
Auth0ContextInterfaceprovides 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, callgetAccessTokenSilentlyor something, and rerender when the user is fetched. however, this isnt always possible, for instance tanstack router'sbeforeLoadmethod is a place where it would be really useful toawaita 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.getUsermethod, 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.getUserthere really isnt much to test here.Checklist
getAccessTokenWithPopup