@sendhome/common 1.0.167 → 1.0.168
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,8 @@ exports.checkUserAccess = void 0;
|
|
|
4
4
|
const checkUserAccess = (requiredAccountType, requiredLevels) => {
|
|
5
5
|
return (req, res, next) => {
|
|
6
6
|
const { account_type, provider_level = '', admin_level = '' } = req.currentUser; // Default to empty string if undefined
|
|
7
|
+
console.log("req.currentUser", req.currentUser);
|
|
8
|
+
console.log("requiredLevels", requiredLevels);
|
|
7
9
|
// Check if the user's account_type matches the required account_type
|
|
8
10
|
if (account_type !== requiredAccountType) {
|
|
9
11
|
return res.status(403).send({ error: 'You do not have the necessary permissions to access this resource' });
|
|
@@ -11,13 +13,13 @@ const checkUserAccess = (requiredAccountType, requiredLevels) => {
|
|
|
11
13
|
// Check provider levels for 'provider' users
|
|
12
14
|
if (account_type === 'provider' && (requiredLevels === null || requiredLevels === void 0 ? void 0 : requiredLevels.provider)) {
|
|
13
15
|
if (!requiredLevels.provider.includes(provider_level)) {
|
|
14
|
-
return res.status(403).send({ error: 'Provider level not authorized for this
|
|
16
|
+
return res.status(403).send({ error: 'Provider level not authorized for this resource' });
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
// Check admin levels for 'admin' users
|
|
18
20
|
if (account_type === 'admin' && (requiredLevels === null || requiredLevels === void 0 ? void 0 : requiredLevels.admin)) {
|
|
19
21
|
if (!requiredLevels.admin.includes(admin_level)) {
|
|
20
|
-
return res.status(403).send({ error: 'Admin level not authorized for this
|
|
22
|
+
return res.status(403).send({ error: 'Admin level not authorized for this resource' });
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
next();
|