# Auth0 redirect not working in chrome while using nodejs as backend and react js on front-end

**URL:** <https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416>\
**Category:** Get Help\
**Tags:** sdks-quickstarts, auth0-react\
**Created:** [March 13, 2023, 2:17pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416 "2023-03-13T14:17:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 13, 2023, 2:17pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/1 "2023-03-13T14:17:02Z")

</div>

We have been facing the above mentioned issue from the starting but now it has become our only reason not to use auth0 for authorization. We need the solution for the problem ASAP as we need to roll out our product which is development ready and up for testing .

**The issue :-**  
When the user logs in using email and password in the chrome browser, the access token present in the redirect URL is not being resolved . The reason is unknown and we are not getting any errors in the console also . We had done our research in the respective field and found that it might happen due to some adblocker but we removed all the extensions present in the chrome browser . This not only happens on chrome but also on safari so please can anyone help us out .

Thank you

---

<div class="post-metadata">

**Author:** ![dylan.sebastianmte](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dylan.sebastianmte/32/45450_2.png) [@dylan.sebastianmte](https://community.auth0.com/u/dylan.sebastianmte)\
**Post date:** [March 15, 2023, 1:48am UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/4 "2023-03-15T01:48:58Z")

</div>

Lo solucioné pasando las credenciales en index.js con Auth0Provider de la siguiente forma:

const root = ReactDOM.createRoot(document.getElementById(‘root’));  
root.render(  
\<React.StrictMode\>  
  
  
  
\</React.StrictMode\>  
);

En mi caso el problema era que habia escrito redirectUrl en lugar de redirectUri

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [March 15, 2023, 1:10pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/5 "2023-03-15T13:10:23Z")

</div>

Thanks for sharing that with the rest of community!

---

<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:** [March 16, 2023, 5:30pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/7 "2023-03-16T17:30:27Z")

</div>

Hi @nishit,

Can you provide some additional info about the following statement?

> the access token present in the redirect URL is not being resolved

What do you mean by “Not being resolved”?

Can you also give an example of the response you are seeing?

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 16, 2023, 5:54pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/8 "2023-03-16T17:54:57Z")

</div>

Ideally whenever the user logs in using his email-id and password they get redirected to the redirect-uri along with the code which then further authenticate user with access token. But in chrome specifically the user is getting stuck at the redirect-uri (the one with the code) but the work flow works just fine in other browsers and also the social login works great with all the browsers.  
P.S:We are using Auth0-provider react sdk.

---

<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:** [March 16, 2023, 6:38pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/9 "2023-03-16T18:38:39Z")

</div>

Could you please provide a [HAR file](https://auth0.com/docs/troubleshoot/troubleshooting-tools/generate-and-analyze-har-files) of the behavior and **send it to me in a DM**?

---

<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:** [March 22, 2023, 9:31pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/11 "2023-03-22T21:31:47Z")

</div>

Thanks for sending that over.

I had a chance to look at the file, and I see some odd behavior. Could you please share the details of your implementation? A code snippet is a good place to start. Particulary in how you are handling the auth `code`.

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 24, 2023, 9:21am UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/12 "2023-03-24T09:21:21Z")

</div>

Hey Dan,  
So glad to hear back from you , so here is how we handle the auth code that is redirected to us by auth0 we call getAccessTokenSilently() function of “@auth0/auth0-react” react library below is the code snippet provided . The function return us the access token and id token . Below is the representation of request and response:-

REQUEST:-

```auto
{
"client_id":`${clientID}`,
"code_verifier":`${code_verfier}`,
"code":`${code}`,
"redirect_uri":`${redirect_uri}`
}

```

NOTE :- the actual values are replaced with the variables (for privacy reasons).

RESPONSE:-

```auto
{
"access_token":`${access_token}`,
"id_token":`${id_token}`,
"scope":`openid profile email offline_access`,
"expires_in":86400,
"token_type":"Bearer"
}

```

Code snippet used in the frontend

1. Below code describes how we initialize the Auth0Provider:-

```auto
<React.StrictMode>
  <Auth0Provider
    domain=`${domain}`
    clientId=`${clientID}`
    redirectUri=`${redirect_uri}`
    audience=`${audience}`
    scope="openid profile email offline_access"
    cacheLocation="localstorage"
  >
    <BrowserRouter>
      <App />
    </BrowserRouter>
  </Auth0Provider>
</React.StrictMode>

```

2.This is how we handle the code with getAccessTokenSilently() function.

```auto
const { isAuthenticated, logout, loginWithRedirect, getAccessTokenSilently } =
      useAuth0();

  const fetchAccessTokenAuth0 = async () => {
    const GATS = await getAccessTokenSilently();
    return GATS;
  };

  useEffect(() => {
    if (isAuthenticated) {
      async function asyncTokenFetch() {
        const fat0 = await fetchAccessTokenAuth0();
        await globalInfo.setAccessTokenAuth0(fat0);
        localStorage.setItem("accessTokenSaasDen", fat0);
      }

      asyncTokenFetch();
    }
  }, [isAuthenticated]);

```

and an additional query is it secured to store the access token in local storage?

let us know if you need anything else from us to solve the issue .

Thanks again

---

<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:** [March 24, 2023, 1:50pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/13 "2023-03-24T13:50:17Z")

</div>

FYI, the SDK has token caching built in to getAccessTokenSilently. When it fetches a token, it sets it in the specified cacheLocation and only retrieve a new one when the existing token is no longer valid. No need to handle that manually.

I’m seeing requests to a `/loading-tokens` endpoint. Is that something you’ve done in your app?

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 24, 2023, 4:34pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/14 "2023-03-24T16:34:31Z")

</div>

Yeah the `/loading-tokens` endpoint is a route made on frontend which has the 2nd code snippet from the previous reply.

The main problem arises when the user tries to login in chrome the function getAccessTokenSilently() is not called probably.

---

<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:** [March 24, 2023, 4:38pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/15 "2023-03-24T16:38:10Z")

</div>

In the HAR you sent, it looks like the request gets hung up on that endpoint.

Did you follow one of our quickstarts when setting up the app? You shouldn’t need to handle the code and verifier at all, the SDK does all of that for you.

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 24, 2023, 5:01pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/16 "2023-03-24T17:01:27Z")

</div>

We followed the quickstarts but we needed to store the access token explicitly to send it to the backend api calls, this method work great for other browsers but for chrome it doesn’t.

---

<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:** [March 24, 2023, 5:03pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/17 "2023-03-24T17:03:24Z")

</div>

> [@nishit](#):
>
> we needed to store the access token explicitly to send it to the backend api calls

The SDK is doing this exactly. Can you show the code that is hitting that endpoint?

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 24, 2023, 5:13pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/18 "2023-03-24T17:13:48Z")

</div>

This method is working fine with other browsers but only have the problem in chrome can you specify why is that.

The request is stuck on this url

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/a/aa50eb250eda074557c596fb19148847473fcc0c.png)

and here is the network tab

 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/7/a7fd807ea16ad32978d8c660b10a1163cf9b1cd3.png)

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [March 24, 2023, 5:15pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/19 "2023-03-24T17:15:47Z")

</div>

Here is the image of the network tab in firefox where it works correctly

 ![image (2)](https://global.discourse-cdn.com/auth0/original/3X/4/4/4424d695b53aa70b23c45698171d4c5185b60e0d.png)

---

<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:** [March 24, 2023, 6:38pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/20 "2023-03-24T18:38:57Z")

</div>

Yes, I’ve looked at the HAR. It appears something in your code prevents the rest of the flow from completing, and considering it is ending on the non-auth0 endpoint `/loading-tokens`, I would start there.

Can you share what is happening in your code at that endpoint?

Also, a HAR from another browser, with it working, could be useful.

I would also suggest removing the redundant behavior in your app (i.e. fetchAccessTokenAuth0, GATS, etc.)

---

<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:** [March 27, 2023, 2:00pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/21 "2023-03-27T14:00:07Z")

</div>

Hi @nishit,

Thanks for sending that over.

I noticed a few potential issues while looking at those captures:

- Your app is incorrectly registered as a _Regular Web App_. If you are running a SPA (React), it should be registered as such.
- You are missing the _Allowed Web Origins_ in your application settings. Without this, you will not be able to refresh silently.
- You are requesting refresh tokens, but not receiving them. If you look at the request, you aren’t returned a refresh token at any point.
- You are storing access tokens in localstorage. This is generally considered a bad practice.

The problems logging in may be a result of the Allowed Web Origins settings, but it could be unrelated.

I would highly recommend following our [React Quickstart](https://auth0.com/docs/quickstart/spa/react/01-login) for setting up your app, as it appears you are missing several pieces of the boilerplate setup, and are including some anti-patterns that should be avoided.

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [April 7, 2023, 8:39am UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/22 "2023-04-07T08:39:28Z")

</div>

Hey Dan, I implemented the first and second points and configured my app as per the React Quickstart as well. Can you explain how I can implement the rest (bypass the local storage and still get access tokens at any point)?

Given below is the new code for the Provider:

```auto
import React from "react";
import * as ReactDOMClient from 'react-dom/client';
import App from "./App";
import { Auth0Provider } from "@auth0/auth0-react";
import { clientID, domain } from "../src/API";
import { BrowserRouter } from "react-router-dom";

const root = ReactDOMClient.createRoot(document.getElementById("root"));

root.render(
  <React.StrictMode>
    <Auth0Provider
      domain={domain}
      clientId={clientID}
      audience="https://www.saasden.club"
      authorizationParams={{
        redirect_uri: "https://saasden.club/loading-tokens",
      }}
    >
      <BrowserRouter>
        <App />
      </BrowserRouter>
    </Auth0Provider>
  </React.StrictMode>
);

```

---

<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 7, 2023, 2:42pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/23 "2023-04-07T14:42:43Z")

</div>

Great!

For the access token, please see the [Get an access token](https://auth0.com/docs/quickstart/spa/react/02-calling-an-api#get-an-access-token) section of the quickstart. It demonstrates how to retrieve the token.

---

<div class="post-metadata">

**Author:** ![nishit](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nishit/32/45056_2.png) [@nishit](https://community.auth0.com/u/nishit)\
**Post date:** [April 8, 2023, 8:17pm UTC](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416/24 "2023-04-08T20:17:36Z")

</div>

This is the error I encountered after completing all the steps.

 ![image](https://global.discourse-cdn.com/auth0/original/3X/7/a/7a02f90ebab5d10a97e7c251d8158e340c50ad70.png)

I looked for a similar issue on the internet but couldn’t find a reliable answer. What exactly is this error, and how can it be avoided? What else needs to be changed?

[Next page](https://community.auth0.com/t/auth0-redirect-not-working-in-chrome-while-using-nodejs-as-backend-and-react-js-on-front-end/102416.md?page=2)
