[Done] Advanced Node and Express - Set up the Environment

Hi @dxabier,

I don’t have any problems getting the console log for the connected user. My only issue was with the “error” messages when I ran the test-suite.

As suggested by others here, adding the following in server.js (placed at the top along with the other dependency requirements) solved the test-suite problems for me:

const cors = require("cors");
app.use(cors());

Alternatively, app.use(cors()) can be added to the fccTesting.js file, where const cors = require('cors') is already present. It seems the author simply forgot to the the app to use CORS.

The issue has been flagged on GitHub: https://github.com/freeCodeCamp/boilerplate-socketio/issues?utf8=✓&q=

2 Likes

Hello @lieberscott,

Thank you for your answer! I forgot again about the “cors” instantiation again in this challenge and didn’t pass for me either. Solved it after requiring and instantiation. Some past challenges had this problem also and I solved them after adding “cors” but with so many things to look out for I got stuck on this one because of this.
I’ll put in on a sticky note on my monitor as a reminder and all of you should do so :slight_smile:

Cheerio!

if you’re still having the same problem can you share your auth.js file as well

Thanks for your response pmayur. I had moved on to other projects as I didn’t want to spend too much time on this, but this was my auth.js:
this is my glitch project: https://glitch.com/edit/#!/user-auth-ex?path=server.js:1:100:

const session     = require('express-session');
const mongo       = require('mongodb').MongoClient;
const passport    = require('passport');
const GitHubStrategy = require('passport-github').Strategy;

module.exports = function (app, db) {
  
    app.use(passport.initialize());
    app.use(passport.session());

    passport.serializeUser((user, done) => {
      done(null, user.id);
    });

    passport.deserializeUser((id, done) => {
        db.collection('chatusers').findOne(
            {id: id},
            (err, doc) => {
                done(null, doc);
            }
        );
    });

    passport.use(new GitHubStrategy({
        clientID: process.env.GITHUB_CLIENT_ID,
        clientSecret: process.env.GITHUB_CLIENT_SECRET,
        callbackURL: "https://buttercup-delete.gomix.me/auth/github/callback"
      },
      function(accessToken, refreshToken, profile, cb) {
          db.collection('chatusers').findAndModify(
              {id: profile.id},
              {},
              {$setOnInsert:{
                  id: profile.id,
                  name: profile.displayName || 'Anonymous',
                  photo: profile.photos[0].value || '',
                  email: profile.emails[0].value || 'No public email',
                  created_on: new Date(),
                  provider: profile.provider || '',
                  chat_messages: 0
              },$set:{
                  last_login: new Date()
              },$inc:{
                  login_count: 1
              }},
              {upsert:true, new: true}, //Insert object if not found, Return new object after modify
              (err, doc) => {
                  return cb(null, doc.value);
              }
          );
        }
    ));
  
}

Hi stevenYouhana
pretty sure at this point it is your callback URL
callbackURL: "https://buttercup-delete.gomix.me/auth/github/callback"
which you need to change and enter the URL of your project instead,
callbackURL: "https://user-auth-ex.glitch.me//auth/github/callback"
also can you check if your client id and clientsecret are present in the .env file along with the session_secret, I think that should fix it

That went completely unnoticed. Thanks for pointing this out. :slight_smile:

Did pass the tests using this code snippet! :slight_smile: Thanks!

I’m at the last test of Advanced Node and Express my code is working but still fcc is generating an error on the send and display chat messages challenge: see my code at glitch:

Another peculiarity I found out and which may be useful, is that the same code may ot may not pass the tests if formatted with the glitch “Format this file”…

1 Like

You are a lifesaver, thanks for pointing this out. I would never have thought to look for that in fcctesting.js and this has made everything work for me.

Cheers, worked fine!

Thanks for your answer

#Gratitude
I really appreciate this, it worked for me.