@modernlock/common 1.0.66 → 1.0.68
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/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -58,3 +58,4 @@ __exportStar(require("./mqtt/mqtt-wrapper"), exports);
|
|
|
58
58
|
__exportStar(require("./things/commands"), exports);
|
|
59
59
|
__exportStar(require("./@types/notification"), exports);
|
|
60
60
|
__exportStar(require("./@types/express"), exports);
|
|
61
|
+
__exportStar(require("./middlewares/serviceAuth"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
2
|
type Role = "superAdmin" | "developer" | "supportAgent";
|
|
3
|
-
declare const
|
|
4
|
-
export {
|
|
3
|
+
declare const verifyAdminPermission: (role: Role[]) => (req: Request, res: Response, next: NextFunction) => void;
|
|
4
|
+
export { verifyAdminPermission };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.verifyAdminPermission = void 0;
|
|
4
4
|
const authorization_error_1 = require("../errors/authorization-error");
|
|
5
|
-
const
|
|
5
|
+
const verifyAdminPermission = (role) => {
|
|
6
6
|
return (req, res, next) => {
|
|
7
7
|
var _a;
|
|
8
8
|
// if (!role.includes(req.user.role)) throw new AuthenticationError();
|
|
@@ -12,4 +12,4 @@ const verifyPermission = (role) => {
|
|
|
12
12
|
next();
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
|
-
exports.
|
|
15
|
+
exports.verifyAdminPermission = verifyAdminPermission;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authenticateTokenServices = void 0;
|
|
4
|
+
const jwtEncryption_1 = require("../utils/jwtEncryption");
|
|
5
|
+
const authenticateTokenServices = (req, res, next) => {
|
|
6
|
+
const authHeader = req.headers.authorization;
|
|
7
|
+
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
8
|
+
return res.status(401).json({ message: "Unauthorized: No token provided" });
|
|
9
|
+
}
|
|
10
|
+
const token = authHeader.split(" ")[1];
|
|
11
|
+
try {
|
|
12
|
+
const decoded = (0, jwtEncryption_1.jwtDecrypt)(token);
|
|
13
|
+
req.user = decoded; // attach user info to request
|
|
14
|
+
next();
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
return res.status(403).json({ message: "Forbidden: Invalid or expired token" });
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
exports.authenticateTokenServices = authenticateTokenServices;
|