Log out route
router.get('/logout', (req, res) => { delete req.session.returnTo; req.flash('success', 'Successfully Logged Out!'); req.session.destroy(); res.redirect('/home'); }) Route for rendering home view
app.get('/home',(req,res) =>{ const isLoggedIn = req.session.user ? true : false; res.render('home', { isLoggedIn }); }) Home view
<% } if (!isLoggedIn) { %> <% if (success.length > 0 ) {%> <div class="alert alert-success alert-dismissible fade show" role="alert"> <%= success %> <alert type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></alert> </div> <% } %> <% } %> Explaination of main issue
My flahes are working fine for every other route and view for example login and signup the only issue i am facing is that in my logout route after deleting the session the flash message does not appear
when i removed the code req.session.destroy(); the flash message worked fine i a;so searched internet to find solution but didnt find something usefull. your help will be appreciated a lot.
req) in a code? I mean, do you currently have working a code where there are two (or more) request?express-sessionandconnect-flash? Share the code about these two configurations.The flash is a special area of the session used for storing messages.andFlash messages are stored in the session., so it would absolutely make sense that it doesn't work anymore after destroying the session.