I'm having problems authenticating through Google OAuth api on a website hosted on Heroku.
Everything works in my localhost. This is my configuration on google dev console.
It works on localhost. It doesn’t work online. This is the error I got.
I've tried using http
as suggested in some old thread on stack overflow, but it didn't work.
I've tried changing the allowed redirect url in the google console to include also the port, and in that case it worked.
The problem is that I don't know which port Heroku is going to use every time the server restart.
Do you know any workaround to a such situation?
Well, at the end I didn't figure out how to configure properly Google... so what I did (and it worked) was to remove the port from the return url:
const strategyConfig = {
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_SECRET_ID,
callbackURL: process.env.NODE_ENV === "production"
? `${HOST}/${RETURN_URL}`
: `${HOST}:${PORT}/${RETURN_URL}`,
passReqToCallback: true,
};