I want to check whether user is logged in or not. If the user is not logged in I want to restrict the access. I've used express-rate-limit and setting the rate limit inside if statement but its not working.
It works fine I put that outside if
Any suggestions?
console.log("Routing");
console.log(req.originalUrl);
if(req.cookies['session-token']){
res.locals.isLoggedIn = true
}else{
console.log("Enter into rate limit");
rateLimit({
windowMs: 12 * 60 * 60 * 1000, // 12 hour duration in milliseconds
max: 1,
message: "You exceeded 100 requests in 12 hour limit!",
headers: true,
})
res.locals.isLoggedIn = false
}
next()
})```