Am using express-session in my project its working fine, if user logged in to my site means I stored their data in session and after logout destroyed session, thats also working fine, after logout if user run particular url means that will take user to that page without log in, need to restrict that one, below is my tried code
app.use((req,res,next)=>{
if(!req.session.data)
{
return res.redirect("/"); or res.redirect("/"); //Both not working
}
next();
})
this shows the below error
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:491:11)
at ServerResponse.setHeader (_http_outgoing.js:498:3)
at ServerResponse.header (/home/djaxtech/Documents/luka-asset/node-app/node_modules/express/lib/response.js:767:10)
at ServerResponse.send (/home/djaxtech/Documents/luka-asset/node-app/node_modules/express/lib/response.js:170:12)
at done (/home/djaxtech/Documents/luka-asset/node-app/node_modules/express/lib/response.js:1004:10)
at tryHandleCache (/home/djaxtech/Documents/luka-asset/node-app/node_modules/ejs/lib/ejs.js:257:5)
Anyhelp appreciated..!