You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently ran into an infinite loop scenario where I needed to get the token and pass it with the user object to another function inside useEffect. That function is memoized in useCallback, with only navigate (react-router-dom) dependency. The only variable element in the useEffect dependency array is the user object from useAuth0.
I looked at the code, and the reducer is setting the user object to a newly decoded one from getUser on each GET_ACCESS_TOKEN_COMPLETE action. This action is called every time with getAccessTokenSilenty, in the finally block. This means it's impossible to retrieve the access token alone, without regenerating the user object.
I know there are many ways to solve this, but I think there shold be an option or a new method that simply returns the access token without tempering with the user object. I'm guessing the reason behind doing it the current way is to keep the user object in sync with the decoded token claims. If not, it makes no sense to update the user object, considering how React works.
I simply need to get the token to make an API request. I shouldn't have to worry about the user object in the process.
Describe the ideal solution
add a new method, that only fetches the token, without updating the user context, like getAccessTokenOnly.
update reducer logic to compare previous state with action payload, but this would break current user expectations
memoize the user in the provider
Ideally, if there is a relationship between the access_token and the user, the solution will come from the vanilla js package.
Alternatives and current workarounds
I am calling the js sdk manually in this case, inside useEffect. I actually rebuilt the react package, but the reducer logic and provider are the same, as far as this feature is concerned. I instantiate the client outside of the context, and let the provider closer over it.
Additional context
No response
The text was updated successfully, but these errors were encountered:
Checklist
Describe the problem you'd like to have solved
I recently ran into an infinite loop scenario where I needed to get the token and pass it with the user object to another function inside useEffect. That function is memoized in useCallback, with only navigate (react-router-dom) dependency. The only variable element in the useEffect dependency array is the user object from useAuth0.
I looked at the code, and the reducer is setting the user object to a newly decoded one from getUser on each GET_ACCESS_TOKEN_COMPLETE action. This action is called every time with getAccessTokenSilenty, in the finally block. This means it's impossible to retrieve the access token alone, without regenerating the user object.
I know there are many ways to solve this, but I think there shold be an option or a new method that simply returns the access token without tempering with the user object. I'm guessing the reason behind doing it the current way is to keep the user object in sync with the decoded token claims. If not, it makes no sense to update the user object, considering how React works.
I simply need to get the token to make an API request. I shouldn't have to worry about the user object in the process.
Describe the ideal solution
Ideally, if there is a relationship between the access_token and the user, the solution will come from the vanilla js package.
Alternatives and current workarounds
I am calling the js sdk manually in this case, inside useEffect. I actually rebuilt the react package, but the reducer logic and provider are the same, as far as this feature is concerned. I instantiate the client outside of the context, and let the provider closer over it.
Additional context
No response
The text was updated successfully, but these errors were encountered: