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

Any calls made to my passport.authenticate() middleware deletes and recreates my req.session object. I

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745173035a4615042.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信