@modernlock/common 1.0.67 → 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);
|
|
@@ -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;
|