Node.JS session without cookies
Asked Answered
L

2

5

I have been trying but I have found out that iOS 5 by default doesn't accept cookies. I have been trying many different things even using Redis but still cannot get a session to persist for more than one request.

Without using cookies, what other session options do I have? I am about to roll a crude session module using Redis where I just send my own "session id" to and from but that seems like it could easily brake.

Lumberman answered 17/2, 2012 at 4:30 Comment(0)
T
5

If you cannot get the client to support cookies, perhaps you can put some data into LocalStorage, and then communicate that up to the server to connect to the session, and structure it like a single-page app.

It'd look something like this:

server                            |         client
send initial payload, with token  -->       store token in LocalStorage
initial payload contains some script

                                 <-- XHR request for /data?sessid=XXXXX
look up session, do stuff        -->  handle result, update DOM, do more XHR  

Are web sockets supported? You could use Socket.io to do the transport, which would be a lot less latency.

Tridimensional answered 17/2, 2012 at 4:42 Comment(0)
V
2

I am almost sure you will want to use cookies. The other alternative would be to append a session id to every request via a url param and persist this across your app leveraging some kind of middleware to make sure its appended to every URL. You could do this by parsing your responses or by hijacking your template engine to include this in every link and form. I find it really strange the iOS doesn't havent cookies. I am almost sure that this is incorrect, can you please link where you read that?

Varicocele answered 17/2, 2012 at 4:39 Comment(1)
Actually your post about rolling your own session thingy is almost exactly what I have done. Ill link you on github. You should be able to persist it in local storage. I didn't see that this is most likely sencha. Check this out ----> gist.github.com/1155365Varicocele

© 2022 - 2024 — McMap. All rights reserved.