shuttlepro-shared 1.1.5 → 1.1.7
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.
- package/middlewares/checkPermission/index.js +14 -22
- package/package.json +1 -1
- package/utils/index.js +3 -4
|
@@ -24,29 +24,21 @@ exports.checkPermission = async (req, res, next, values) => {
|
|
|
24
24
|
if (body) {
|
|
25
25
|
const { module, action } = values;
|
|
26
26
|
const moduleObj = getModule(body, module);
|
|
27
|
-
if (moduleObj) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return next();
|
|
42
|
-
} else {
|
|
43
|
-
return res.status(HttpStatusCode.UNAUTHORIZED).json({
|
|
44
|
-
code: HttpStatusCode.UNAUTHORIZED,
|
|
45
|
-
message: GenericMessages.PERMISSION_DENIED,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
27
|
+
if (moduleObj && moduleObj.includes(action)) {
|
|
28
|
+
req.user = {
|
|
29
|
+
id: body.id,
|
|
30
|
+
type: body.type,
|
|
31
|
+
email: body.email,
|
|
32
|
+
firstName: body.firstName,
|
|
33
|
+
lastName: body.lastName,
|
|
34
|
+
suspended: body.suspended,
|
|
35
|
+
isVerified: body.isVerified,
|
|
36
|
+
role: body.role,
|
|
37
|
+
isMember: body.isMember,
|
|
38
|
+
uuid: body.uuid,
|
|
39
|
+
};
|
|
40
|
+
return next();
|
|
48
41
|
} else {
|
|
49
|
-
console.log("here");
|
|
50
42
|
return res.status(HttpStatusCode.UNAUTHORIZED).json({
|
|
51
43
|
code: HttpStatusCode.UNAUTHORIZED,
|
|
52
44
|
message: GenericMessages.PERMISSION_DENIED,
|
package/package.json
CHANGED
package/utils/index.js
CHANGED
|
@@ -3,7 +3,6 @@ const jwt = require("jsonwebtoken");
|
|
|
3
3
|
exports.getBodyFromDecodeToken = (token) => {
|
|
4
4
|
try {
|
|
5
5
|
const decoded = jwt.decode(token, { complete: true });
|
|
6
|
-
console.log(decoded, "decoded");
|
|
7
6
|
if (decoded && decoded.payload) {
|
|
8
7
|
return decoded.payload || null;
|
|
9
8
|
}
|
|
@@ -17,9 +16,9 @@ exports.getBodyFromDecodeToken = (token) => {
|
|
|
17
16
|
exports.getModule = (obj, module) => {
|
|
18
17
|
return (
|
|
19
18
|
(obj &&
|
|
20
|
-
obj.
|
|
21
|
-
obj.
|
|
22
|
-
obj
|
|
19
|
+
obj.permission &&
|
|
20
|
+
obj.permission.length > 0 &&
|
|
21
|
+
obj.permission[module]) ||
|
|
23
22
|
null
|
|
24
23
|
);
|
|
25
24
|
};
|