22 lines
497 B
TypeScript
22 lines
497 B
TypeScript
export function checkAuthentication(req: any, res: any, next: Function) {
|
|
if (req.isAuthenticated()) {
|
|
//req.isAuthenticated() will return true if user is logged in
|
|
next();
|
|
} else {
|
|
res.redirect('/auth/login');
|
|
}
|
|
}
|
|
|
|
// const checkIsInRole = (...roles) => (req, res, next) => {
|
|
// if (!req.user) {
|
|
// return res.redirect('/login')
|
|
// }
|
|
|
|
// const hasRole = roles.find(role => req.user.role === role)
|
|
// if (!hasRole) {
|
|
// return res.redirect('/login')
|
|
// }
|
|
|
|
// return next()
|
|
// }
|