Saturday, 18 March 2017

hapijs yar doesn't work

I am having this in one handler (api/user/login):

 request.yar.set('userSession', {userId: doc.userId});
 console.log(request.yar.get('userSession'));

in second handler I have this (api/user/isLoggedIn):

 console.log(request.yar.get('userSession'));

when I go in browser and do this in console:

$.ajax({
url: 'http://localhost:3004/api/user/login',
method: 'POST',
data: {
    email: 'durisvk2@gmail.com',
    password: 'jjuurr123'
},
success: function(data) {
    console.log(data);
}
})

the server outputs: {userId: 'ASDFGHJKLZX'}

BUT when I do this in Chrome Console:

$.ajax({
url: 'http://localhost:3004/api/user/isLoggedIn',
method: 'GET',
data: {
},
success: function(data) {
    console.log(data);
}
})

I get in console undefined

why isn't it storing session from one request to another?



via durisvk10

No comments:

Post a Comment