Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

req.session is undefined in POST requests - SailsJS

this 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, res) -> // POST app.com/accounts/login
        log 2, req.session // 2, undefined

Why is this happening?

I'm using io.socket.get & io.socket.post on the client to send these requests

session config

module.exports.session = 
    secret: 'bb8775b377f1e8e198b864f8fdacbb9e'

I also noticed that response functions such as res.forbidden & res.ok etc were also absent, maybe its more sensible to assume that for some reason the whole request is malformed. so if you're having any trouble with that, try my answer, it may help you

like image 988
iConnor Avatar asked Mar 16 '26 19:03

iConnor


1 Answers

The only solution i found to this was to switch out io.socket.post to

io.socket.request({url: '/accounts/login', method: 'POST'});

Worked like a charm

like image 115
iConnor Avatar answered Mar 18 '26 15:03

iConnor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!