I have a simple login script. I created a method in the SessionController called create to handle logins. I do all the needed validation and then set the user as active and save them. I also use User.publishUpdate()
to send the message back to the client.
The problem is that I recieve no messages at all. When the page is loaded I call User.subscribe(req.socket, users);
for all users so they are all subscribed. Not really sure why the messages aren't sent.
I am using sails 0.10.0.
This is the subscribe method which is called on page load:
User.find({}).exec(function (error, users) {
if (error) {
res.json({
error: error
});
}
// Subscribe to the model class
User.subscribe(req.socket);
// subscribe to the model instance
User.subscribe(req.socket, users);
res.send(200);
});
And the create method for logins (removed code that doesn't pertain to this question):
user.active = true;
req.session.authenticated = true;
req.session.User = user;
user.save(function (error, user) {
if (error) {
res.send(error, 500);
}
User.publishUpdate(user.id, {
loggedIn: true,
id: user.id,
action: ' has logged in'
});
res.json(user, 200);
});
I am sending the request via sockets to the subscribe and login methods
socket.get('/user/subscribe');
socket.get('/session/create', {//stuff}, callback)