# From auth0-js to auth0-react, jwt audience invalid

**URL:** <https://community.auth0.com/t/from-auth0-js-to-auth0-react-jwt-audience-invalid/74745>\
**Category:** Get Help\
**Tags:** jwt, auth0\
**Created:** [December 13, 2021, 5:26pm UTC](https://community.auth0.com/t/from-auth0-js-to-auth0-react-jwt-audience-invalid/74745 "2021-12-13T17:26:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paxatax](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/paxatax/32/33718_2.png) [@paxatax](https://community.auth0.com/u/paxatax)\
**Post date:** [December 13, 2021, 5:26pm UTC](https://community.auth0.com/t/from-auth0-js-to-auth0-react-jwt-audience-invalid/74745/1 "2021-12-13T17:26:53Z")

</div>

I recently switched a legacy web app from using the auth0-js NPM package to auth0-react. I followed Auth0’s React guide ([available here](https://auth0.com/blog/complete-guide-to-react-user-authentication/)). I believe my frontend code is in order, however when I try to wire up an existing API, I now get a 401-unauthorized, with the response saying “jwt audience invalid. expected: …”.

I console logged the JWT token (screenshots below), and the overall structure of the decoded payload has changed, with the previous audience value now becoming the azp value. You can see that the value in the response value is the same as the aud and azp. Could someone please give me a little guidance on what is going on here?

Thank you in advance.

- **Which SDK this is regarding:**  
auth0-react

- **SDK Version:**  
v^1.8.0

- **Platform Version:**  
Node 15.14.0, NPM 7.7.6

**Screenshots**  
auth0-js  
 ![auth0-js](https://global.discourse-cdn.com/auth0/original/3X/6/3/63fad4b1722d3639c966ad37d28b270937aed53c.png)

auth0-react  
 ![auth0-react](https://global.discourse-cdn.com/auth0/original/3X/6/0/606e0531cd14629aeb8004e835941a4521cdc98a.png)

Response  
 ![401-unauthorized](https://global.discourse-cdn.com/auth0/original/3X/4/5/451c240d0334e12d31029051b92d2d4915a2f571.png)

**Code**  
// Provider

```auto
const Auth0ProviderWithHistory = ({ children }) => {
  const domain = config.auth0Domain;
  const clientId = config.auth0ClientId;

  const history = useHistory();

  const onRedirectCallback = (appState) => {
    history.push(appState?.returnTo || window.location.pathname);
  };

  return (
    <Auth0Provider
      domain={domain}
      clientId={clientId}
      redirectUri={window.location.origin}
      onRedirectCallback={onRedirectCallback}
      audience={config.auth0Audience}
      scope="openid email profile"
    >
      {children}
    </Auth0Provider>
  );
};

export default Auth0ProviderWithHistory;

```

// index.js

```auto
ReactDOM.render(
	<BrowserRouter>
		<Auth0ProviderWithHistory>
				<Provider store={store}>
					<App />
				</Provider>
		</Auth0ProviderWithHistory>
	</BrowserRouter>,

	document.getElementById('root'),
);

```

// App.js

```auto
const { isAuthenticated, loginWithRedirect, isLoading } = useAuth0()

useEffect(() => {
    if (!isAuthenticated && !isLoading) {
      loginWithRedirect();
    }
  }, [isLoading])

useEffect(() => {
    console.log('Logged in==>', {user});
  }, [user])

```

// File where API call is made

```auto
createTripRequest = async (reqBody) => {
        const { user, getAccessTokenSilently } = this.props.auth0;
        try{
            const token = await getAccessTokenSilently({
                audience: `https://${config.auth0Domain}/userinfo`,
                scope: 'openid email profile',
            });
            axios.post(`${config.apiUrl}/passengers/${user.sub}/requests`, reqBody, { headers: { 'Authorization': `Bearer ${token}` } })
            .then(() => {
                //
            })

```

---

<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:** [December 13, 2021, 6:05pm UTC](https://community.auth0.com/t/from-auth0-js-to-auth0-react-jwt-audience-invalid/74745/3 "2021-12-13T18:05:02Z")

</div>

Hi @paxatax,

It looks like you are mixing up the ID token and the Access Token.

The payload from auth0-js that you shared looks like an ID token, and the payload from auth0-react appears to be an access token.

The audience claim is used to indicate the intended consumer of the token; the ID token consumed by the client app and the access token consumed by the backend/API.

---

<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:** [April 8, 2022, 4:27pm UTC](https://community.auth0.com/t/from-auth0-js-to-auth0-react-jwt-audience-invalid/74745/4 "2022-04-08T16:27:40Z")

</div>


