Error: failed to fetch user profile

Hi @anygamecounter, welcome to the community! Could you please try to console.log() prior to this? You could also check tenant logs to see if your login was successful and a user profile should be available.

Let’s start here, and if nothing interesting shows up, a HAR file could help (

P.S. Could you also check this quickstart (specifically, the /callback route implementation):

I used the quickstart to set everything up.
The Login and Authorization exchange was successful.

1 Like (274.0 KB)

Got it, thank you for clarification. So, something goes wrong within the callback itself. Any clues in the Dev Tools Console? Network Tab?

I just uploaded the Har file

1 Like

Looks like your /callback redirects back to login screen, creating a login loop. You get correct JWT in response, cookies all set up correctly, session is in place. My only guess would be that there’s a redirect to login screen. Could you check this please? Alsom console logging user object first thing in the passport.authenticate of callback route could provide some clues as well.

1 Like

The code I have is the same as the quickstart for /callback

I also get the User Profile, I did the console.log earlier to try to find the issue and it comes back correctly

So what I am seeing is, it keeps trying to forward the User Profile to /User but is not able to and ends up passing the rate limit.

The only error I am receiving is the following.

Error: failed to fetch user profile
at /var/www/app/node_modules/passport-auth0/lib/index.js:181:28
at passBackControl (/var/www/app/node_modules/oauth/lib/oauth2.js:132:9)
at IncomingMessage. (/var/www/app/node_modules/oauth/lib/oauth2.js:157:7)
at IncomingMessage.emit (events.js:322:22)
at endReadableNT (_stream_readable.js:1187:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)

I also just did a test and it goes straight to‘login’); instead of req.login

if (err) { return next(err); }
if (!user) { return res.redirect(’/login’); }
req.logIn(user, function (err) {

Any ideas on what could be causing this?

This is the console.log(user)

I just tried reproducing the issue and could get this error when I used “Download Sample” option of the quickstart at Could you please try doing this?

You want me to “Download Sample”?

There are multiple things that could be going wrong with your code. Downloading a sample (and making sure it works) rules out some of the potential network and package incompatibility issues, while also providing an easy-to-follow reference implementation that could possible point you in the right direction.

As an alternative, you could create a github repo with your app and I could try reproducing the issue on my end.

Alright, when I get the chance, I’ll download the sample and give it a try.
I have AnyGameCounter on Github but unfortunately I’m not able to give access.

– GG2015

hold on, I think I managed to get into a similar loop. Double checking.

1 Like

Thank you Art, I’ve made progress.

I still am having issues but I need to edit it to work with my code.
I will let you know if I solve the issue fully.


So, a few things I just discovered, although I’m not getting the exact same error as you (I couldn’t reproduce it in a “clean” setup after all). The whole flow should work fine locally without changes. However, when an env set to production, make sure that you set up:

app.set('trust proxy', 1); // critical for heroku and some other providers
sess.proxy = true

Also, make sure you have state: true in your Auth0Strategy object.

Please let me know if it helps.

I made a lot of progress but I got set back to the same issue.
I’ll send you a DM that contains information to see the issue first hand.


1 Like

I have the code you quoted added, it does seem to help.