0

I have defined in passport.js file a function called issueToken(user, done). In server.js I have the following code:

require('./config/passport')(passport);
require('./app/routes.js')(app, passport);

In routes.js, I am trying to call the issueToken function:

module.exports = function(app, passport) {
   ...
   passport.issueToken(req.user, function(err, token) {
   ...
   }
}

However it seems it is not the correct function call since it returns the following error: TypeError: undefined is not a function at Object.handle (/home/octavian/Desktop/node/login2/app/routes.js:54:12) (the line containing the issueToken function call above).

Any clues on what is the correct syntax for the call I'm trying to make?

Thanks

1 Answers1

0

There is a zillion ways to export stuff from a Node module, but that is out of the scope of your question. You are using a pattern that is completely fine.

Your real problem is not the export pattern in the module itself or the invocation pattern in server.js, but the fact that the object passport that you are passing as an argument does not have an issueToken method, so that is what you should debug and figure out what's happening.

Faris Zacina
  • 14,056
  • 7
  • 62
  • 75
  • Well it should have that method, since I have defined it in passport.js. – octavianmm Aug 19 '15 at 10:32
  • Try to debug the prototype of the passport object, and i am sure you will find that it is not there :) You can list the functions on the object by using underscore _.functions(passport) – Faris Zacina Aug 19 '15 at 10:49
  • I'm trying to debug as you said, but I can't list the functions.....where exactly should I enter _.functions(passport), in the node debug console? – octavianmm Aug 19 '15 at 11:03
  • You need to use the underscore library to be able to do that or see some alternatives here: http://stackoverflow.com/questions/4352997/how-to-list-the-functions-methods-of-a-javascript-object-is-it-even-possible – Faris Zacina Aug 19 '15 at 11:08