last day (15 days later) » 

20:37
-1
Q: req.session is undefined in POST requests - SailsJS

iConnorthis is my current controller and the result of the logs is the problem. log = console.log.bind(console) module.exports = test: (req, res) -> res.ok() current: (req, res) -> // GET app.com/accounts/current log 1, req.session // 1, Object Session login: (req, re...

because the session isn't being sent with the login post request? maybe the middleware handling sessions isn't touching post requests? who knows. not enough information.
@KevinB yes, but why wouldn't it be? it does with GET
Because the client didn't send it? you have provided no proof that the client has sent the session information with the request.
@KevinB but it should, you're not funny
Right no there's no way of knowing whether the problem is with this code, or the code that is sending the request. That has to be determined first. start with the source of information, the client.
20:37
I told you in question im using io.socket.get & io.socket.post now it automatically works properly with get, but not POST, io.socket.?
@KevinB so thats why i'm asking on here because io.socket is not my code so how would i know
You could try using a different client to get/post to the server to see if it behaves the same way
@KevinB ill try postman now
Theoretically, it should behave the same way, assuming you send the same headers with postman that io.socket.* is.
@kevinB it works with postman, so must be sails client code, this is what i'm saying
What type of session store are you using?
20:37
@KevinB default i've added my session config to Q
hi
The primary difference i see between the postman client and io.socket.get/post is that io.socket.get/post uses websockets, while postman uses http. with http requests, the session is handled through a cookie that is set and sent automatically, i'm not sure if the same is happening with io.socket
i know
but
io.socket.get requests can access session fine
whereas
io.socket.post can not
you've tried swapping the order of the two right? it's not that it's undefined on first request but defined after that, right?
and the get is still websocket
ill check headers
socket is not showing up in network
hmm
no the socket is
but not each request
go to your localstorage and add a property named debug and set it equal to true
see if that gives you more information about the requests being sent
20:47
ive done that
but anyway
found more info in websocket frames
and all request show up apart from the GET
how strange
however
the headers in POST request is empty
this is what the frame shows
421["post",{"method":"post","headers":{},"data":{"email":"[email protected]","password":"sfdfsadsfa"},"url":"accounts/login"}]
That's to be expected i think, if you aren't logged in yet, you don't have a session, right?
i don't think it's that simple though.
The session is usually created with the first request to the server, all subsequent requests would contain the session information
yes exactly
Note that socket requests with sails.js don't use the cookie to send the session
Im not actually setting any session data, just logging
but the docs don't specify what it uses instead, i assume it's part of the socket connection.
20:52
ill change login to GET
see what happens
21:33
Solved
thanks for ur time

last day (15 days later) »