wikijs-fork/server/middlewares/auth.js

34 lines
595 B
JavaScript
Raw Normal View History

2017-12-24 05:34:47 +00:00
/* global wiki */
2017-04-02 23:56:47 +00:00
2016-08-17 00:56:55 +00:00
/**
* Authentication middleware
*/
module.exports = (req, res, next) => {
2017-02-09 01:52:37 +00:00
// Is user authenticated ?
2016-08-17 00:56:55 +00:00
2017-02-09 01:52:37 +00:00
if (!req.isAuthenticated()) {
2017-12-24 05:34:47 +00:00
if (wiki.config.auth.public !== true) {
2017-04-02 23:56:47 +00:00
return res.redirect('/login')
} else {
2017-12-24 05:34:47 +00:00
// req.user = rights.guest
2017-04-02 23:56:47 +00:00
res.locals.isGuest = true
}
} else {
2017-04-02 23:56:47 +00:00
res.locals.isGuest = false
2017-02-09 01:52:37 +00:00
}
2016-08-17 00:56:55 +00:00
2017-02-09 01:52:37 +00:00
// Check permissions
2016-08-17 00:56:55 +00:00
2017-12-24 05:34:47 +00:00
// res.locals.rights = rights.check(req)
2017-04-02 23:56:47 +00:00
2017-12-24 05:34:47 +00:00
// if (!res.locals.rights.read) {
// return res.render('error-forbidden')
// }
2017-02-09 01:52:37 +00:00
// Expose user data
2016-08-17 00:56:55 +00:00
2017-02-09 01:52:37 +00:00
res.locals.user = req.user
2016-08-17 00:56:55 +00:00
2017-02-09 01:52:37 +00:00
return next()
}