scroggins
scroggins

Reputation: 105

Accessing the session on socket requests with sails.js

When making a client request using io.socket such as;

io.socket.post('activity/subscribe')

There is no session information appended to the request object in sails causing my authentication policies to fail.

This is not a cross-domain request and the sails.sid cookie has been set. I'm using redis as a session store and for XHR requests the session is populated correctly.

My understanding is that sails handles the integration of sockets so that when a requests reached the app's routes it can be treated like any other request?

I've had a look at the answer in Sails.js authorization for socket requests but that fails as req.socket.manager is not defined. Maybe that's for an older version of sails? Am in v0.11.0.

After sending the post request, I see the following in the console:

verbose: Receiving incoming message from Socket.io:  { method: 'post',
  headers: {},
  data: {},
  url: 'activity/subscribe' }
verbose: Interpreting socket.io message as virtual request to "post activity/subscribe"...
error: policy error here as no session..

Upvotes: 1

Views: 649

Answers (1)

ejwallace
ejwallace

Reputation: 26

We figured it out eventually...

'activity/subscribe' - no good

'/activity/subscribe' - yay

Upvotes: 1

Related Questions