StephenGrider / FullstackReactCode

Companion repo to https://www.udemy.com/node-with-react-fullstack-web-development
1.39k stars 1.17k forks source link

auth/google/callback timeout issue #13

Open beardedguru opened 6 years ago

beardedguru commented 6 years ago

I've gone through the code you supplied here twice, replacing all of the steps that you have and cannot get this timeout issue corrected. When you click to login it just hangs and then heroku pushes application error page.

Git link to project: https://github.com/beardedguru/emaily-app

Api is enabled inside of google developer:

image

Restrictions are setup as follows:

image

Have triple checked heroku environment details and they are correct.

Any help would be appreciated.

beardedguru commented 6 years ago

Here are the logs in Heroku:

2018-01-17T00:57:54.000000+00:00 app[api]: Build succeeded
2018-01-17T00:58:10.423138+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-01-17T00:58:10.536514+00:00 heroku[web.1]: Process exited with status 143
2018-01-17T00:58:12.418420+00:00 heroku[web.1]: Starting process with command `npm start`
2018-01-17T00:58:14.511322+00:00 app[web.1]: 
2018-01-17T00:58:14.511355+00:00 app[web.1]: > server@1.0.0 start /app
2018-01-17T00:58:14.511356+00:00 app[web.1]: > node index.js
2018-01-17T00:58:14.511358+00:00 app[web.1]: 
2018-01-17T00:58:16.048894+00:00 heroku[web.1]: State changed from starting to up
2018-01-17T00:58:22.356506+00:00 heroku[router]: at=info method=GET path="/auth/google" host=guarded-harbor-22727.herokuapp.com request_id=99d5db32-27c3-4431-a400-a1193e794f7c fwd="24.196.182.143" dyno=web.1 connect=1ms service=17ms status=302 bytes=389 protocol=https
2018-01-17T00:58:26.669532+00:00 app[web.1]: (node:20) DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html
2018-01-17T00:58:56.416346+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/auth/google/callback?code=4/6N9-MU89l3hIOOnttCP904oKO_4xoeLL0OWcwC5LgWU" host=guarded-harbor-22727.herokuapp.com request_id=5e64fae9-5ce3-43ac-837a-a29e7fe3fb54 fwd="24.196.182.143" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0 protocol=https
2018-01-17T01:03:43.592681+00:00 heroku[router]: at=info method=GET path="/" host=guarded-harbor-22727.herokuapp.com request_id=5490dad5-824b-433a-9727-ad9e5eee8154 fwd="24.196.182.143" dyno=web.1 connect=1ms service=7ms status=404 bytes=383 protocol=https
2018-01-17T01:03:47.178286+00:00 heroku[router]: at=info method=GET path="/auth/google" host=guarded-harbor-22727.herokuapp.com request_id=92defdb7-cd27-446f-b4a3-ba25ff0660e2 fwd="24.196.182.143" dyno=web.1 connect=2ms service=4ms status=302 bytes=389 protocol=https
2018-01-17T01:04:37.883969+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=GET path="/auth/google/callback?code=4%2FqtPXXKM3A1BlIberq4yo6RFAmNyi8XxoB3Gg-k6c5uc" host=guarded-harbor-22727.herokuapp.com request_id=d0c65ee0-1704-42b7-afd6-4168a1462662 fwd="24.196.182.143" dyno=web.1 connect=1ms service=30001ms status=503 bytes=0 protocol=https
5975471 commented 6 years ago

Hi, did you solved this problem? If so, and you have a some guide how it can be done - I'd appreciate it. Thanks in advance.

sergio-vb commented 6 years ago

I currently have exactly the same problem!

sergio-vb commented 6 years ago

Solved it, here's what worked for me:

Please check that your user/password for the mlab prod database correctly match the MONGO_URI variable that you set in Heroku, that was causing this issue for me. I think it's easy to make a typo here since you cannot see the password for the database user after you create it. Also note that the user should not be "read-only", and that this is not the same user/password combination that you use to log in to mlab.

I found that the reason why the authentication callback was failing with a timeout error was that the Google Strategy's callback defined in the file passport.js never called the method done(). This, in turn, happened because the query to find a user in the MongoDB never completed because Mongoose couldn't connect to the mlab.com database. I tried creating a new user for the prod database in mlab and updating that in the Heroku environment variables and it worked!

nikolapalibrk commented 6 years ago

I have the same issue, checked all and the credentials are fine, also tried with different user for database, but it still hangs on for a while on google sign in page and after certain time application breaks.

gabrielzzarate commented 6 years ago

Yeah I am having the same issue as described above. The request to 'auth/google' just hangs while in production.

neone35 commented 6 years ago

My problem was that database had IP whitelist with local IP only (e.g. 78.44.44.144). Solution was to create separate project and cluster (I use Mongo Atlas with free cluster) and whitelist all IPs with 0.0.0.0 rule for production. I also gave admin user privilege to write/read on production and mongoAdmin in development with max priorities.

Ph3bian commented 6 years ago

i'm having the same issue and i have made sure my credentials match in heroku

dtfialho commented 6 years ago

I was having this problem and i was able to fix it by doing these steps:

My password had an '@' on it, so when i tried to connect, moongose gave me and error message. Instead of using a string with the whole url + user + password to connect, i added the mlab url user and password to my keys and changed a bit the connect method to:

mongoose.connect(keys.mongoUri, { user: keys.mongoUsername, pass: keys.mongoPassword });

Ok, after this, i started the application and had another error and after a few trys and some changes to see what happens, i found that the url nedded a prefix in order to connect. Before the fix my url was like something.mlab.com:47619/my-app then i changed to mongodb://something.mlab.com:47619/my-app and everything started to work correctly.

I hope it helps.

tonic0water commented 6 years ago

Had the same issue, removing '@' in the mlab password fixed the issue

pal-p commented 6 years ago

Have the exact same problem. my db username and password have no special chars and i have checked for typos several times. So still wondering what is causing this

FaisalAli19 commented 6 years ago

I had the same issue. As @IvanArredondo mention removing @ from mlab password fixed the issue.

gskalyan90 commented 6 years ago

I got the same issue, created a new user and password and changed that in the heroku variables. It worked

andyprickett commented 5 years ago

Same here. Had a '$' in my password. Deleted that database user, created a new one with no special characters in the password, problem solved.

mouten57 commented 5 years ago

Had the same issue here! Was driving myself crazy until I realized I forgot to add a user to my production database. It seems like the user issue is a common problem across the board :)

If you're still having issues, check all of your keys, uris, usernames, and passwords..for MLab and Google especially.

ebassity commented 5 years ago

My problem was that database had IP whitelist with local IP only (e.g. 78.44.44.144). Solution was to create separate project and cluster (I use Mongo Atlas with free cluster) and whitelist all IPs with 0.0.0.0 rule for production. I also gave admin user privilege to write/read on production and mongoAdmin in development with max priorities.

neone35's solution worked for me. Created a separate project in Atlas for prod, set user to read/write, whitelisted all IPs with 0.0.0.0/0 and voila.

NiMaGangFour commented 5 years ago

Same here. Had a '$' in my password. Deleted that database user, created a new one with no special characters in the password, problem solved.

Have the exact same problem. my db username and password have no special chars and i have checked for typos several times. So still wondering what is causing this

It works!!! Just make sure there is no any special chars in your MongoDB.Atlas database user's password. (Delete all special chars like "!, @, # $, : ,+ , =" .etc) Note: The database user's password may not the password which you sign in MongoDB.Atlas.

exanoid commented 5 years ago

My problem was that database had IP whitelist with local IP only (e.g. 78.44.44.144). Solution was to create separate project and cluster (I use Mongo Atlas with free cluster) and whitelist all IPs with 0.0.0.0 rule for production. I also gave admin user privilege to write/read on production and mongoAdmin in development with max priorities.

This solution is working for me, thanks @neone35 But you don't need to create another project, just whitelist IP 0.0.0.0 to your current one.

LeBaron88 commented 4 years ago

My problem was that database had IP whitelist with local IP only (e.g. 78.44.44.144). Solution was to create separate project and cluster (I use Mongo Atlas with free cluster) and whitelist all IPs with 0.0.0.0 rule for production. I also gave admin user privilege to write/read on production and mongoAdmin in development with max priorities.

This solution is working for me, thanks @neone35 But you don't need to create another project, just whitelist IP 0.0.0.0 to your current one.

This solution is also working for me here, thanks guys. Got stuck for hours but knew the issue was with the DB. Now I can move on... really appreciated.

djangowiki commented 4 years ago

None of the solution worked for me. I just didn't push my changes to heroku. The files on my localhost isn't the same with the files on heroku. I just ran a commit and ran git push heroku master and it worked. Make sure to be pushing your local files to heroku after any changes.

sudhir9297 commented 4 years ago

My problem was that database had IP whitelist with local IP only (e.g. 78.44.44.144). Solution was to create separate project and cluster (I use Mongo Atlas with free cluster) and whitelist all IPs with 0.0.0.0 rule for production. I also gave admin user privilege to write/read on production and mongoAdmin in development with max priorities.

this worked for me ....thankyou so much

Acnologiaxx commented 4 years ago

My problem was that database had IP whitelist with local IP only (e.g. 78.44.44.144). Solution was to create separate project and cluster (I use Mongo Atlas with free cluster) and whitelist all IPs with 0.0.0.0 rule for production. I also gave admin user privilege to write/read on production and mongoAdmin in development with max priorities.

thank you sir. this solved my problem