Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate Token Retrieval from User Update #787

Open
5 tasks done
JANA-itsaishvili opened this issue Jul 12, 2024 · 0 comments
Open
5 tasks done

Separate Token Retrieval from User Update #787

JANA-itsaishvili opened this issue Jul 12, 2024 · 0 comments

Comments

@JANA-itsaishvili
Copy link

Checklist

  • I have looked into the Readme, Examples, and FAQ and have not found a suitable solution or answer.
  • I have looked into the API documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

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

  • 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

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

No branches or pull requests

1 participant