HeideQueen
9/18/2019 - 12:16 AM

flash messages

const flash	= require('connect-flash');

app.use(flash());

app.use((req, res, next) => {
	res.locals.currentUser = req.user;
	res.locals.success = req.flash('success');
	res.locals.error = req.flash('error');
	next();
});

middlewareObj.isLoggedIn = (req, res, next) => {
	if (req.isAuthenticated()) {
		return next();
	}
	req.flash('error', 'You must be logged in to do that!');
	res.redirect('/login');
};

<div class="container">
		<% if (success && success.length > 0) { %>
			<div class="alert alert-success" role='alert'>
			<%= success %>
			</div>
		<% } %>
		<% if (error && error.length > 0) { %>
		<div class="alert alert-danger" role='alert'>
		<%= error %>
		</div>
		<% } %>
	</div>