# Error: Consent required. localhost. Code examples to grant user consent during development

**URL:** <https://community.auth0.com/t/error-consent-required-localhost-code-examples-to-grant-user-consent-during-development/111314>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-react\
**Created:** [July 14, 2023, 8:45pm UTC](https://community.auth0.com/t/error-consent-required-localhost-code-examples-to-grant-user-consent-during-development/111314 "2023-07-14T20:45:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![globalmax](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@globalmax](https://community.auth0.com/u/globalmax)\
**Post date:** [July 14, 2023, 8:45pm UTC](https://community.auth0.com/t/error-consent-required-localhost-code-examples-to-grant-user-consent-during-development/111314/1 "2023-07-14T20:45:34Z")

</div>

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.

```auto
    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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [July 17, 2023, 2:31pm UTC](https://community.auth0.com/t/error-consent-required-localhost-code-examples-to-grant-user-consent-during-development/111314/3 "2023-07-17T14:31:23Z")

</div>

Hi @globalmax,

Welcome to the Auth0 Community!

The best way to avoid getting consent prompt errors for first party applications being developed locally is to modify your `/etc/hosts` file. More details here:

> **[User Consent and Third-Party Applications](https://auth0.com/docs/get-started/applications/confidential-and-public-applications/user-consent-and-third-party-applications#skip-consent-for-first-party-applications)**
>
> Learn how to decouple APIs from applications that consume them and define third-party apps that you don't control or may not trust.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [July 31, 2023, 2:32pm UTC](https://community.auth0.com/t/error-consent-required-localhost-code-examples-to-grant-user-consent-during-development/111314/4 "2023-07-31T14:32:23Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
