Quality Assurance: Set up the environment

Hi I am running the test trying to log in to github and I am not passing the last one “Your client should connect to your server.” I set up in secrets my GITHUB_CLIENT_ID and my GITHUB_CLIENT_SECRET is this my normal login of github? any ideas why it is not working?
my replit notebook
my auth.js:

const LocalStrategy = require('passport-local');
const bcrypt = require('bcrypt');
const { ObjectID } = require('mongodb');
const GitHubStrategy = require('passport-github').Strategy;

module.exports = function (app, myDataBase) {
 passport.serializeUser((user, done) => {
   done(null, user._id);
 });

 passport.deserializeUser((id, done) => {
   myDataBase.findOne({ _id: new ObjectID(id) }, (err, doc) => {
       if (err) return console.error(err);
       done(null, doc);
   });
 });

 passport.use(new LocalStrategy((username, password, done) => {
   myDataBase.findOne({ username: username }, (err, user) => {
     console.log(`User ${username} attempted to log in.`);
     if (err) { return done(err); }
     if (!user) { return done(null, false); }
     if (!bcrypt.compareSync(password, user.password)) { 
       return done(null, false);
     }
     return done(null, user);
   });
 }));

 passport.use(new GitHubStrategy({
   clientID: process.env.GITHUB_CLIENT_ID,
   clientSecret: process.env.GITHUB_CLIENT_SECRET,
   callbackURL: 'https://boilerplate-advancednode.eriglesias.repl.co/auth/github/callback'
   },
   function (accessToken, refreshToken, profile, cb) {
     console.log(profile);
     myDataBase.findAndModify(
       { id: profile.id },
       {},
       {
         $setOnInsert: {
           id: profile.id,
           name: profile.displayName || 'Er Iglesias',
           photo: profile.photos[0].value || '',
           email: Array.isArray(profile.emails) ? profile.emails[0].value : 'No public email',
           created_on: new Date(),
           provider: profile.provider || ''
         }, $set: {
           last_login: new Date()
         }, $inc: {
           login_count: 1
         }
       },
       { upsert: true, new: true },
       (err, doc) => {
         return cb(null, doc.value);
       }
     );
   }
 ));
}

I didn’t look at all the code carefully or test anything but you are missing something in client.js - review the latter part of the challenge text.

Also, just in the future please link to the editor and not the preview page on Replit.

https://replit.com/@eriglesias/boilerplate-advancednode?v=1

1 Like

Hi larsjorg thank for for looking at the issue, I checked the code and I still can’t get in with Github I tried changing the socket in client.js to let socket = io.connect('https://github.com/'); but when I click github it says github.com refuses to connect do you know where I could locate the error?

You still haven’t changed the client.js code.


Now for the client to connect, you just need to add the following to your client.js which is loaded by the page after you’ve authenticated:

/*global io*/
let socket = io();

“Your client should connect to your server.”
This is completely unrelated to github or github login.
Github related code in this project is only used for login through github.

The failed test depends on io.connect(), which is used in this project to connect the client to the same server.

Note: io() works only when connecting to a socket hosted on the same url/server. For connecting to an external socket hosted elsewhere, you would use io.connect('URL'); .

Since you are trying to connect to the same server for the chat application instead of github or some other domain, you shouldn’t do this
let socket = io.connect('https://github.com/');

This connects to github instead of your server. You should be using
let socket = io();

Thanks!! I will give it a better look to see what is failing with the io()