Hi all,
I understand that consent is required when serving in development, but I can’t find any clear code examples in the docs or community for granting the consent when this error occurs on localhost in development. I would love to see a clear example of how to handle this error, so I can get the jwt to call my server in development.
const fetchUsers = async () => {
try {
const options = { authorizationParams: { audience: process.env.REACT_APP_AUTH0_AUDIENCE } };
const token = isAuthenticated ? await getAccessTokenSilently(options) : "";
console.log(token,' token')
const userGetResp = await axios.get(entityListUrlSelected, {
headers: {
Authorization: `Bearer ${token}`,
}
});
setUsers(userGetResp.data)
} catch (err) {
console.log(err);
if (err.message === "Consent required") {
// I would expect this pop up to show up and allow me to grant consent when in localhost for development
// So that I can test api calls using a jwt to protected endpoints.
// I can see the network call works and the token is correct, but getAccessTokenSilently always throws the above error
loginWithPopup({
audience: process.env.REACT_APP_AUTH0_AUDIENCE,
scope: "openid profile email",
prompt: "consent",
});
}
}
}
fetchUsers();
more context using the react Auth0Provider:
const onRedirectCallback = (appState) => {
window.history.replaceState(
{},
document.title,
appState?.returnTo || window.location.pathname
);
};
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<Provider store={store}>
<BrowserRouter>
<PersistGate loading={null} persistor={persistor}>
<Auth0Provider
domain={domain}
clientId={clientId}
audience={audience}
scope="openid profile email"
onRedirectCallback={onRedirectCallback}
redirectUri={window.location.origin}
prompt="consent"
Any feedback would be greatly appreciated.