【问题标题】:Allow nodejs sessions to carry over to subdomains允许 nodejs 会话转移到子域
【发布时间】:2015-02-24 14:29:33
【问题描述】:

我正在努力理解 nodejs 中的会话,我在同一个端口上有一个子域,但我必须再次登录。

我想知道如何配置nodejs来共享同一个会话,我正在使用passportjs来登录用户。

我试过用redis,但是不行,看不懂。

app.use(session({ 
  secret: "something", 
  domain: '.app.localhost',
  store : new RedisStore({
    host: '.app.localhost',
    port : 9200 ,
    client: redisClient
  }),
  cookie : {
    maxAge : 604800 // one week
  }
}));

如何让我的子域 app.localhost 与 localhost 共享相同的登录会话?

【问题讨论】:

  • 有人知道吗?你能指出我正确的方向吗?

标签: javascript node.js redis passport.js


【解决方案1】:

假设您必须使用express-session 包。如何挂载系统厨师所指的域是这样的。

app.use(session({ 
  secret: "something", 
  // domain: '.app.localhost', <-- This Don't put into the cookie
  store : new RedisStore({
    host: '.app.localhost',
    port : 9200 ,
    client: redisClient
  }),
  cookie : {
    maxAge : 604800 // one week
    domain: 'app.localhost', //<-- This put into the cookie the domain
  }
}));

【讨论】:

    猜你喜欢
    • 2010-10-13
    • 2014-08-03
    • 2023-04-04
    • 2020-07-02
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多