Freecodecamp - Implementation of Social Authentication II

Hello, I’ve been stuck for 5 days in this freecodecamp challenge. My code seems to be running fine but I can’t get pass this challenge. I you can give me some help please.

This is my code so far:

‘use strict’;

const express = require(‘express’);
const bodyParser = require(‘body-parser’);
const fccTesting = require(’./freeCodeCamp/fcctesting.js’);
const session = require(‘express-session’);
const mongo = require(‘mongodb’).MongoClient;
const passport = require(‘passport’);
const GitHubStrategy = require(‘passport-github’).Strategy;

const app = express();

fccTesting(app); //For FCC testing purposes

app.use(’/public’, express.static(process.cwd() + ‘/public’));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.set(‘view engine’, ‘pug’)

mongo.connect(‘dbConn’, (err, db) => {
if(err) {
console.log('Database error: ’ + err);
} else {
console.log(‘Successful database connection’);

    app.use(session({
      secret: 'lll',
      resave: true,
      saveUninitialized: true,
    }));
    app.use(passport.initialize());
    app.use(passport.session());
  
    function ensureAuthenticated(req, res, next) {
      if (req.isAuthenticated()) {
          return next();
      }
      res.redirect('/');
    };

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

    passport.deserializeUser((id, done) => {
        db.collection('socialusers').findOne(
            {id: id},
            (err, doc) => {
                done(null, doc);
            }
        );
    });
  
    passport.use(new GitHubStrategy({
        clientID: '**clientId**',
        clientSecret: '**clientSecret**',
        callbackURL: "https://myappfcc.glitch.me/auth/github/callback"
      },
      function(accessToken, refreshToken, profile, cb) {
          console.log(profile);
          db.collection('socialusers').findAndModify(
              {id: profile.id},
              {},
              {$setOnInsert:{
                  id: profile.id,
                  name: profile.displayName || 'John Doe',
                  photo: profile.photos[0].value || '',
                  email: 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}, //Insert object if not found, Return new object after modify
              (err, doc) => {
                  return cb(null, doc.value);
              }
          );
        }
    ));
  
    app.route('/auth/github')
      .get(passport.authenticate('github'));
  
    app.route('/auth/github/callback')
  .get(passport.authenticate('github', {failureRedirect: '/'}),
  (req, res) => {
    res.redirect('/profile');
});
  
  
    app.route('/')
      .get((req, res) => {
        res.render(process.cwd() + '/views/pug/index');
      });

    app.route('/profile')
      .get(ensureAuthenticated, (req, res) => {
           res.render(process.cwd() + '/views/pug/profile', {user: req.user});
      });

    app.route('/logout')
      .get((req, res) => {
          req.logout();
          res.redirect('/');
      });

    app.use((req, res, next) => {
      res.status(404)
        .type('text')
        .send('Not Found');
    });
  
    app.listen(process.env.PORT || 3000, () => {
      console.log("Listening on port " + process.env.PORT);
    });  

}});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0.

Challenge: Implementation of Social Authentication II

Link to the challenge:

did you find your issue? I am running into the same thing on this test.

I was running into this same issue. It looks like you’ve got to be spot on with what you type. I was able to get pass it by using single quotes on my callbackURL. see below:

passport.use(new GitHubStrategy({
    clientID: process.env.GITHUB_CLIENT_ID,
    clientSecret: process.env.GITHUB_CLIENT_SECRET,
    callbackURL: 'https://boilerplate-advancednode.zatorriusf.repl.co/auth/github/callback'
  }