Unable to add audience parameter to getAccessTokenSilently

I am trying to generate a JWT token with the getAccessTokenSilently, but when I try to add the audience parameter to the function I get this error: “No overload matches this call.”.

Here is the react typescript code snippet:

function App() {
const {user, isAuthenticated, isLoading , getAccessTokenSilently} = useAuth0();
const [token, setToken] = useState();
useEffect(() => {
(async () => {
try {
const accessToken: any = await getAccessTokenSilently({
audience: ‘API_IDENTIFIER’
});
setToken(accessToken);
} catch (error) {
console.error(‘Error fetching access token’, error);

  }
})();

}, [getAccessTokenSilently]);

What can I do to fix this?

Hey there @gt2960 !

I’m not positive what that error means, but passing the audience param in authorizationParams may resolve it:

 const accessToken = await getAccessTokenSilently({
          authorizationParams: {
            audience: "API_IDENTIFIER"
          }

Thanks that worked! What should go inside of the “API_IDENTIFIER” field?

Awesome, thanks for confirming!

The API_IDENTIFIER field is the identifier which you give an API when registering it in Auth0:

Does it matter which API I use?

Yes, the audience should be that of the resource server or API the access token is meant to be used to access.