Open JhuneAlfred opened 6 years ago
Can you post your keys.js and your index.js files on here. We could take a look with you. Don't post your key and secret just the code around it.
Here is the keys.js file:
module.export = {
googleClientID: 'xxxxxx',
googleClientSecret: 'xxxxxxx'
}
and below is the index.js
const passport = require('passport')
const GoogleStrategy = require('passport-google-oauth20').Strategy
const keys = require('./config/keys')
const app = express()
passport.use(
new GoogleStrategy(
{
clientID: keys.googleClientID,
clientSecret: keys.googleClientSecret,
callbackURL: '/auth/google/callback'
},
accessToken => {
console.log(accessToken)
})
)
app.get('/auth/google',
passport.authenticate('google', {scope: ['profile', 'email']
}))
app.get('/auth/google/callback',
passport.authenticate('google', {
successRedirect: '/profile',
failureRedirect: '/fail'
})
)
const PORT = process.env.PORT || 5000
app.listen(PORT)
I'm just another course student, all looks good to me. My only suggestion at this stage would be a direct authentication method if you haven't already. So in the strategy apply the key values directly
clientID: "yourclientidstring".
Will at least let you know it's not the path to config/keys and rule out that file for errors.
Just a note on this course, Steven did say he rarely checks github comments but if you send him a message and tell him your issue is here he will check it out.
I placed the ID and Secret directly within the index.js file and issue is resolved. I just need to figure out why it's not reading the values in the keys.js.
Great. Well it's hopefully simple. Check spelling on folders as well as files this often gets missed and the path ./ only works if they folder is at same level as file using it. Good luck.
module.export
should be module.exports
with an s, I think this minor typo may be breaking your keys.js
file's ability to be required in index.js
😃
I had the same issue..., no typos or anything, as I even tried copy pasting the code directly from his github.
Edit: I just noticed when consoled the process.env.NODE_ENV in there, it is showing as if it was in production. That would explain why we are having that issue. Its trying to pull from the ./prod folder instead of ./dev. Edit2: Try starting the server/react with NODE_ENV='development' npm run dev
When testing Oauth, below is the error I am receiving when starting the service:
Oauth2Strategy requires a ClientID option
I followed the instructions discussed in section 3, video 22 (Google Strategy Option).