Search code examples
expresspassport.jspassport-facebook

Express.js using passport-facebook - TypeError: Object 302 has no method 'indexOf'


I've got an express project already running, I'm just trying to hook it up using passport to authenticate through facebook, I've basically copied the example from the github page here:

https://github.com/jaredhanson/passport-facebook

But I'm getting the following error whenever I try to go to the '/auth/facebook' URL in my app:

TypeError: Object 302 has no method 'indexOf'
    at ServerResponse.res.redirect (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/express/lib/response.js:546:13)
    at Strategy.strategy.redirect (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/passport/lib/middleware/authenticate.js:294:15)
    at Strategy.OAuth2Strategy.authenticate (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/passport-facebook/node_modules/passport-oauth2/lib/strategy.js:227:10)
    at Strategy.authenticate (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/passport-facebook/lib/strategy.js:84:41)
    at attempt (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/passport/lib/middleware/authenticate.js:337:16)
    at authenticate (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/passport/lib/middleware/authenticate.js:338:7)
    at callbacks (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/express/lib/router/index.js:171:11)
    at param (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/express/lib/router/index.js:145:11)
    at pass (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/express/lib/router/index.js:152:5)
    at Router._dispatch (/Users/jlawrence/Documents/Websites/Node/Gigster/node_modules/express/lib/router/index.js:179:5)

Solution

  • It could be an incompatibility with older versions of express; you might try updating to express@3.5.x; 3.6 and above deprecated some methods and the refactor might not be worth it.

    Try npm install express@3.5.x, or npm install express@3.5.x -g if it's a global package. Make sure to update the package.json file too.