Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript GitHub Authentication

Nicholas Noochla-or
Nicholas Noochla-or
979 Points

OAuth2Strategy requires a clientID option

I could use some help with this github authentication. I have run a variety of these commands.

SET GITHUB_CLIENT_ID=MYID & GITHUB_CLIENT_SECRET=MYSECRET & npm start

SET GITHUB_CLIENT_ID=MYID & GITHUB_CLIENT_SECRET=MYSECRET & node ./bin/www

C:\Users\Nicholas\repos\passport\OAuthAllSteps\Project\05_inClass\node_modules\passport-oauth2\lib\strategy.js:82
  if (!options.clientID) { throw new TypeError('OAuth2Strategy requires a clientID option'); }
                           ^

TypeError: OAuth2Strategy requires a clientID option

this is how I have defined the options in my app.js file clientID: process.env.GITHUB_CLIENT_ID, clientSecret: process.env.GITHUB_CLIENT_SECRET,

How would I pass in the clientID option? I am not sure what it is asking of me.

2 Answers

At first glance, it looks like you're adding your environmental variables and starting the app concurrently, which is probably not what you want to do.

& - run all scripts concurrently

&& - run scripts sequentially (the next script won't run until the preceding script finishes)

When setting environmental variables, you typical don't use either & or &&. For example:

NODE_ENV=production node app.js

Regardless of sequential vs parallel execution, the best practice is to use the tiny npm package dotenv.

Simply require it at the top of your app.js:

require('dotenv').config();

And create a .env file in the root of your project (important: make sure you add to your .gitignore):

GITHUB_CLIENT_ID=whatever
GITHUB_CLIENT_SECRET=whatever

Make sure that you are typing "clientID", not "clientId". That's my mistake in my case. XD