Miha Šušteršič Miha Šušteršič - 1 year ago 85
Javascript Question

passportJS - passport-facebook cannot GET failureRedirect route

Following the passportJS docs for passport-facebook I am trying to implement express middleware for facebook authentication. I am using mongoose-findorcreate to create the findOrCreate function needed for passportJS.

I am able to redirect to the facebook login form, and login with my facebook credentials. But afterwards I get redirected to the failureRedirect URL which return the following:

Cannot GET

This is my model:

const mongoose = require('mongoose');
const findOrCreate = require('mongoose-findorcreate');

// Schema definition
const userSchema = mongoose.Schema({
provider: String,
id: String,
displayName: String,
name: [
{familyName: String},
{givenName: String},
{middleName: String},
emails: [
{value: String},
{type: String},
photos: [
{value: String},


// Compile model from schema
module.exports = mongoose.model('User', userSchema);

The passport part of the app:

passport.use(new FacebookStrategy({
clientID: conf.facebookClientID,
clientSecret: conf.facebookSecret,
callbackURL: 'http://localhost:3000/auth/facebook/callback',
function(accessToken, refreshToken, profile, done) {
User.findOrCreate(function(err, user) {
if (err) { return done(err); }
done(null, user);

// Authentication routes
app.get('/auth/facebook', passport.authenticate('facebook'));

passport.authenticate('facebook', {
successRedirect: 'http://localhost:3000/words',
failureRedirect: 'http://localhost:3000/auth/facebook',

I am trying to figure out why the login fails, and why the user does not get written into my database (I can query the database for other stuff so I know the connection is valid).

If you need more information about the project please ask and I will edit the question. You can also check the gitHub repo.

Answer Source




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download