0% found this document useful (0 votes)
82 views1 page

Auth

This code defines an access control module that exports an ensureAuthenticated function. The function checks if a request is authenticated, and if so, allows access by calling next(). If not authenticated, it flashes a danger message telling the user to log in, and redirects them to the /users/login page.

Uploaded by

Pedro
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
82 views1 page

Auth

This code defines an access control module that exports an ensureAuthenticated function. The function checks if a request is authenticated, and if so, allows access by calling next(). If not authenticated, it flashes a danger message telling the user to log in, and redirects them to the /users/login page.

Uploaded by

Pedro
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 1

// Access Control

module.exports = {
ensureAuthenticated: function(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
req.flash('danger', 'Please log in to view that resource');
res.redirect('/users/login');
}
};

You might also like