I am facing a strange behavior where I am trying to make two type of login, One with password and other is as Guest. Passport req.logIn() working fine in case of User login with password. But when I am login through guest it set empty Array in session.
Let me show you what details I am giving passport for storing the data.
In case of Registered user
var User = [];
User['email'] = "email@domain.com";
User['id_customer'] = "1";
User['id_user'] = "1";
User['other_info'] = "xyz";
User['other_info'] = "xyz";
User['other_info'] = "xyz";
User['other_info'] = "xyz";
Now in case of Guest User
var User = [];
User['email'] = "email@domain.com";
User['id_guest'] = "1";
User['other_info'] = "xyz";
Passport login ie req.logIn()
is
req.logIn(user, function(err) {
if (err) {
if(err instanceof Error) {
sails.log.debug(err.stack);
} else
{
sails.log.debug(err);
}
res.redirect('index/error');
}
if (req.xhr) {
return res.send({
"success": 1,
"message": info.message,
"user": user
});
} else {
res.redirect('/');
}
});
I am not able to debug why exactly passport do not serializing my Guest user info in right way. Is there any constraint in serializing.
Let me show you my serialize and deserialize methods.
passport.serializeUser(function(user, done) {
// saving Complete User Object in session CouchBase instead of saving
done(null, user);
});
passport.deserializeUser(function(user, done) {
// Getting complete User Object from Couchbase as placed in req for each request
done(null, user);
});
I found the solution. I was making a mistake
I replaced var User = [];
with var User = {};
and it worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.