最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - keepSessionInfo for passport.js not working for versions 0.7-0.6? - Stack Overflow

programmeradmin0浏览0评论

Any calls made to my passport.authenticate() middleware deletes and recreates my req.session object. I need it to stay consistent because it's shared with my socket.io connection. After some digging I've found that the "keepSessionInfo" field is required to disable this behavior, yet it does not work. The solution that did work, was reverting passport to version 0.5.0. Does anyone know why this is? Thanks.

Passport.authenticate() re-creates my session.id

app.post('/user/authenticate', passport.authenticate("local", { keepSessionInfo: true }), (req, res) => {
  console.log("Authenticate success response");
  req.session.isAuthenticatedUser = true;
  // Session ID Changes at this log.
  console.log("Session Id After Authentication", req.session.id)
  res.sendStatus(200);
});

My socket.io Code

// Express Session 
const app = express()
const middleWareSession = session({
  secret: "keyboard cat",
  resave: false,
  saveUninitialized: true,
  rolling: true,
  cookie: { secure: false, httpOnly: false },
});
app.use(middleWareSession);

//Socket.io Handling
const httpServer = createServer(app);
const io = new Server(httpServer, {
  cors: {
    origin: "http://localhost:3000",
    methods: ["GET", "POST"],
    credentials: true,
  },
});
io.engine.use(middleWareSession);
发布评论

评论列表(0)

  1. 暂无评论