javascript - 允许 nodejs session 转移到子域

标签 javascript node.js redis passport.js

我很难理解 nodejs 中的 session ,我在同一端口上有一个子域,但我必须重新登录。

我想知道如何配置 nodejs 以共享同一个 session ,我正在使用 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 与本地主机共享相同的登录 session ?

最佳答案

假设您必须使用 express-session包裹。如何挂载系统 cookes 指的是这个域。

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
  }
}));

关于javascript - 允许 nodejs session 转移到子域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28684308/

相关文章:

redis - 在 Redis 中组织非规范化数据

redis - 无法路由消息进行交换 'bulk' : Table empty or key no longer exists

redis ZRANGEBYLEX 和 ipv6

javascript - 访问 Google Wave 小部件中其他页面的内容?

javascript - 为什么我的计时器需要第二次重新加载才能再次显示/启动?

javascript - 递归函数没有在嵌套循环中被调用

angularjs - Protractor "Can' t 读取未定义的属性 'click'”

javascript - Uncaught ReferenceError : onchange function is not defined (wordpress)

javascript - 仅调整垂直图像的大小

javascript - 当我可以在控制台中看到该值时,为什么我的nodejs postgres函数返回未定义?