@wrcb/cb-common 1.0.686 → 1.0.688
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.
|
@@ -5,29 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.currentUser = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
-
const currentUser = (req,
|
|
8
|
+
const currentUser = (req, res, next) => {
|
|
9
9
|
var _a;
|
|
10
10
|
let token;
|
|
11
|
-
// 1️⃣ Authorization header (Bearer token)
|
|
12
11
|
const authHeader = req.headers.authorization;
|
|
13
|
-
if (authHeader
|
|
14
|
-
|
|
12
|
+
if (authHeader) {
|
|
13
|
+
if (authHeader.startsWith('Bearer ')) {
|
|
14
|
+
token = authHeader.substring(7); // remove "Bearer "
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
if (!token) {
|
|
18
|
+
if ((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt) {
|
|
19
|
+
token = req.session.jwt;
|
|
20
|
+
}
|
|
19
21
|
}
|
|
20
|
-
// Sem token → segue request
|
|
21
22
|
if (!token) {
|
|
22
23
|
return next();
|
|
23
24
|
}
|
|
24
25
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
catch (_b) {
|
|
28
|
-
// Token inválido ou expirado → ignora silenciosamente
|
|
29
|
-
req.currentUser = undefined;
|
|
26
|
+
const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
|
|
27
|
+
req.currentUser = payload;
|
|
30
28
|
}
|
|
29
|
+
catch (error) { }
|
|
31
30
|
next();
|
|
32
31
|
};
|
|
33
32
|
exports.currentUser = currentUser;
|