let sessionMiddleware = expressSession({ secret: 'Tecky Academy teaches typescript', resave: true, saveUninitialized: true, }); app.use(sessionMiddleware); io.use((socket, next) => { let req = socket.request as express.Request; let res = req.res!; sessionMiddleware(req, res, next as express.NextFunction); }); io.on('connection', function (socket) { if(!socket.request.session.user){ socket.disconnect() } });