Greetings! I’m trying to work with React (and the Auth0 React Hook) to access a protected endpoint that I’ve set up locally (for testing/learning purposes).
I’ve got the following function defined in my React component:
const getToken = async () => {
try {
const token = await getAccessTokenSilently({
audience: 'https://codestore.fourthspacegames.com/api',
scope: 'read:test'
});
console.log(token);
} catch (err) {
console.error(err);
}
}
Where the audience
is set to properly match the API I’m working attempting to access, and the scope is theoretically a scope attached to the Admin role that my current logged in user has.
The goal at this point is to just click a button and call getAccessTokenSilently()
to generate the token that I’d need to send to my server (via Bearer?) to make a request to the protected API.
However, when I click said button, it seems to log me out of the app I’m testing it with and therefore throws an error that I’m not logged in and nothing can be generated.
What am I doing wrong?