StephenGrider / FullstackReactCode

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

Oauth2 is not redirecting in production #21

Open timoangerer opened 6 years ago

timoangerer commented 6 years ago

I've followed the tutorial until step 111 ("Testing Deployment") and build a modified version of the app. Everything is working fine in development. But when I deploy to Heroku and then try to initiate the auth flow by clicking on the "/auth/google" link, a blanch screen appears and I'm not redirected.

Interestingly, when I use postman to make a get request at the "/auth/google" endpoint, it returns the HTML and CSS of the google sign in screen.

Does anyone know how to solve this issue? I tried out everything that came to my mind

timoangerer commented 6 years ago

Looks like I'm not the only one having this problem: https://stackoverflow.com/questions/46466198/heroku-node-react-app-anchor-tag-auth-request-unhandled

jaccle commented 6 years ago

I'm having the exact same problem. Followed that link but it was posted 6 months ago :\

timoangerer commented 6 years ago

@missjorie I found that it does work the first time you ever open the production app or if you open it in incognito/private mode.

The problem for me was that after I first clicked on the sign in button, it saved the cookie, also if it was invalid. So passport does not redirect. if you are "already logged in", even if it had just the html of the google sign in as cookie...

Go ahead and use this project for the auth, it works in production https://github.com/thechutrain/mern-passport

dtfialho commented 6 years ago

I just answered it here, i hope it helps.

CatPerry commented 6 years ago

Did anyone find other solutions to this error besides the other replies? (@dtfialho's mLab url prefix and @timoangerer's cookies were not the issues for me.) In production mode on heroku only: After I get through the oauth flow in chrome incognito mode, I get redirected to /surveys# successfully BUT I get an Internal Server Error/white screen that says internal server error.

UPDATE: I went back to my mlab url based on @dtfialho 's suggesttion, but it wasnt the url prefix—it was that I was using the mlab dev url/account rather than the mlab prod url. SO I just changed that and it worked.