Hey, I would like to know how to get the accesToken to use it with axios?! I am using axios hooks to work with axios and fetch data from my API (https://github.com/simoneb/axios-hooks).
But I dont find any way how to get the auth0 token to the hook… any ideas?
It sounds like you would like to include the Access Token you receive from Auth0 as the bearer token in the Authorization requests made by Axios hooks. Is that correct?
It looks like you can include headers in the Request Config object:
I tried that, but I couldnt get it to work… maybe because its an async function to get the token but it looks like I need the token when the axios hook is initialized… I am out of ideas here! I think I cannot use this library!
Also, would you happen to have some code from your app where you are getting the Access Token and sending it an API request? This might help us troubleshoot. Thank you!
I am getting an error when making the component async:
TS2786: ‘GroupsGrid’ cannot be used as a JSX component. Its return type ‘Promise’ is not a valid JSX element. Type ‘Promise’ is missing the following properties from type ‘Element’: type, props, key
Thanks for confirming. I’ve played around with this a bit and I think because useAxios is a hook, it would be challenging to use this with getAccessTokenSilently since you can’t use a hook within useEffect. You may need to use Axios alone within useEffect so that you can get the accessToken before making the request: