hapijs / hapi

The Simple, Secure Framework Developers Trust
https://hapi.dev
Other
14.62k stars 1.34k forks source link

Upgrading from 6.5.x to 8.1.0 returns empty response #2589

Closed shamsher31 closed 9 years ago

shamsher31 commented 9 years ago

We have recently upgraded HAPI version 6.5.1 to 8.1.0. When we send request to HAPI server with user credentials, we validate the user and trying to send user details in reply(user). But the reply returns empty.

AdriVanHoudt commented 9 years ago

make a gist to reproduce this situation, we can only help if you show the code in this case

shamsher31 commented 9 years ago

The reply returns as empty.

Login: function (request, reply) {

    Person.LocalStrategy(request.payload.username, request.payload.password, function (error, userMatch) {

      if (error) {
        request.server.log('error', error);
        loggly.log({'msg' : 'Invalid credentials','error' : error },'basic-login-fail');
        reply(boom.badData('Looks like you\'ve entered your username and password incorrectly.'));
      } else {
        userMatch.scope = userMatch.type;
        request.auth.session.set(userMatch);
        reply(userMatch);
      }

    });
  }
AdriVanHoudt commented 9 years ago

do you get a userMatch back?

shamsher31 commented 9 years ago

This is the userMatch Object

  type: 'User',
  name:
   { 
     id 552f9daa915ebed8d152c07b
     first: 'Sam'
     last: 'Peter',
  },
  scope: 'User' }

I even tried with simply object but did not get any data.

Marsup commented 9 years ago

Where's that function ?

shamsher31 commented 9 years ago

Above function is what I just copied from my application, it doesn't matter what I use.

I even tried with the following:

reply({name : 'abc', id : 1});

and still an empty response.

Marsup commented 9 years ago

That doesn't tell me where it's used.

shamsher31 commented 9 years ago

This is my whole code at one place.

Login: {
    method: 'POST',
    path: '/login',
    config: {
      description: 'Login with Basic Session',
      notes: 'Login authentication route that finds a person with username and password.',
      tags: ['api', 'rest', 'login'],
      auth: {
        mode: 'try',
        strategy: 'Basic'
      },
      validate: {
        payload: {
          username: joi.string().min(2).max(50).required(),
          password: joi.string().min(2).max(30).required()
        }
      },
      handler: function (request, reply) {

        Person.LocalStrategy(request.payload.username, request.payload.password, function (error, userMatch) {

          if (error) {
            request.server.log('error', error);
            loggly.log({'msg' : 'Invalid credentials','error' : error },'basic-login-fail');
            reply(boom.badData('Looks like you\'ve entered your username and password incorrectly.'));
          } else {
            userMatch.scope = userMatch.type;
            request.auth.session.set(userMatch);
            reply({name : 'abc', id : 1});
          }

        });
      }
    }
  }
Marsup commented 9 years ago

I don't remember very well the 6.5.x times but I don't think it ever was supposed to work that way.

hueniverse commented 9 years ago

Did you verify the handler is even called? You will need to go over the breaking changes notes from 7.x and 8.x and apply them, as well as all the changes to all the plugins you are using. Many have changed.

fbaiodias commented 9 years ago

I had the same problem, it was an 'onPreResponse' extension that was calling reply() instead of reply.continue(), thus causing every endpoint to abort prematurely.