You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
548 B
22 lines
548 B
const { hasPermission } = require('../constants/permissions')
|
|
const { authenticateRequest } = require('./session')
|
|
|
|
function requirePermission(...required) {
|
|
return async (req, res, next) => {
|
|
try {
|
|
const account = await authenticateRequest(req)
|
|
if (!hasPermission(account, required)) {
|
|
const error = new Error('没有操作权限')
|
|
error.status = 403
|
|
throw error
|
|
}
|
|
req.operator = account
|
|
next()
|
|
} catch (error) {
|
|
next(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = { requirePermission }
|