Closed shamsher31 closed 9 years ago
make a gist to reproduce this situation, we can only help if you show the code in this case
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);
}
});
}
do you get a userMatch back?
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.
Where's that function ?
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.
That doesn't tell me where it's used.
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});
}
});
}
}
}
I don't remember very well the 6.5.x times but I don't think it ever was supposed to work that way.
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.
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.
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.