Node.JS session without cookies

北城以北 提交于 2019-12-10 15:45:12

问题


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.


回答1:


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.




回答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?



来源:https://stackoverflow.com/questions/9322929/node-js-session-without-cookies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!