assetflow/src/middleware/auth.mw.ts
grey c23b1b306c updated and properly implemented auth middleware AFLOW-32
Co-authored-by: Spacelord <git@spacelord.de>
2023-11-01 20:04:19 +01:00

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()
// }