Session support in Now.js

非 Y 不嫁゛ 提交于 2019-12-01 12:38:07

I ran into this problem and turns out it was happening because I was initializing NowJS before configuring express.

app.configure(function(){
    ...

    app.use(express.cookieParser());
    app.use(express.session({ secret: "my_key", store: redisStore }));
    app.use(app.router);
});

var everyone = nowjs.initialize(app); //must be defined after app.configure

One thing to note is that session is not set until a request is made to the server so if the server is reset, the client socket will reconnect but session will be undefined until the browser does a page refresh.

I managed to find a solution (CoffeeScript), for every "everyone"-request:

self = this
sid = decodeURIComponent(this.user.cookie['connect.sid'])
sessionStore.get sid, (err, session) ->
    self.user.session = session
    <<more code here>>

Any way to get to this.user.session directly?

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