This commit is contained in:
Mr Swift
2024-04-27 20:10:55 +03:30
parent f52f5496c5
commit ee6bd01224
30 changed files with 6503 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
const asyncHandler = require("express-async-handler");
const User = require("../models/userModels");
const hasPerma = (perm) => {
return asyncHandler(async (req, res, next) => {
const user = await User.findId(req.user.id)
if (user && (user.permissions.includes(perm) || !user.permissions.includes("ADMIN"))) {
return next()
} else {
res.status(401); throw new Error('کاربر مجوز لازم را ندارد');
}
})
}
module.exports = { name: "hasPermission", run: hasPerma };