node-oauth2-server icon indicating copy to clipboard operation
node-oauth2-server copied to clipboard

Debug in node console

Open emanuelemoccia opened this issue 10 years ago • 7 comments

How can i remove console.log for errors like 'User and password are invalid' ?? The debug:false value in config is not working??

emanuelemoccia avatar Apr 08 '16 12:04 emanuelemoccia

Which version are you at? 2.x or 3.x?

maxtruxa avatar Apr 11 '16 06:04 maxtruxa

2.4

emanuelemoccia avatar Apr 11 '16 06:04 emanuelemoccia

Are you sure that output is coming from this module? If you pass in anything falsy/nothing for debug an empty function should be used, hence you shouldn't see any output.

Additionally, the output 'User and password are invalid' is nowhere to be found.. If you mean 'Missing parameters. "username" and "password" are required' or 'User credentials are invalid', these are both passed to the next handler that you pass to the grant middleware.

So either your backend (model.getUser) is calling console.log or your error handler is, not this module.

maxtruxa avatar Apr 11 '16 09:04 maxtruxa

Ok, for example, this is the console log:

OAuth2Error: User credentials are invalid at OAuth2Error (/Users/emanuelemoccia/my-project/node_modules/oauth2-server/lib/error.js:30:12) at /Users/emanuelemoccia/my-project/node_modules/oauth2-server/lib/grant.js:228:19 at Query._callback (/Users/emanuelemoccia/my-project/psql2.js:230:13)

and this is my model.GetUser:


`model.getUser = function (username, password, callback) {

  connection.query('SELECT id FROM users WHERE email = ? AND pass_word = ?', [username, password], 
    function (error, results, fields) {
            callback(error, results.length ? results[0] : false);
    }
  );
};`

emanuelemoccia avatar Apr 11 '16 10:04 emanuelemoccia

Yes, that is the error handler middleware. Since it's a middleware, it's only used if you load it yourself (take a look at the redis example). And even if you load it already, that doesn't change that it just calls self.debug which will be a no-op if debug was falsy.

It's likely that you either don't use the error-handling middleware provided by this module, but the default error handler provided by express (or whatever framework you use).

Try the following: Try to output something through the internal debug function of the OAuth server after instanciating it, like this:

var oauth = oauthserver({
  // ...
  debug: false // or null, or undefined, or not specified at all
});

oauth.debug('this is a test');

If you don't see this is a test on your terminal after running the app, the output you see is not coming from this module, but from another error handler down the middleware chain. If that's the case either use the error handler provided by this module as shown in the redis example or write your own, as documented by your framework (for express see here and here).

maxtruxa avatar Apr 11 '16 13:04 maxtruxa

I Solved, you're great thank's a lot.

emanuelemoccia avatar Apr 11 '16 14:04 emanuelemoccia