@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.
@@ -7,4 +7,4 @@ declare global {
7
7
  }
8
8
  }
9
9
  }
10
- export declare const currentUser: (req: Request, _res: Response, next: NextFunction) => void;
10
+ export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
@@ -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, _res, next) => {
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 === null || authHeader === void 0 ? void 0 : authHeader.startsWith('Bearer ')) {
14
- token = authHeader.slice(7);
12
+ if (authHeader) {
13
+ if (authHeader.startsWith('Bearer ')) {
14
+ token = authHeader.substring(7); // remove "Bearer "
15
+ }
15
16
  }
16
- // 2️⃣ Fallback para session (web)
17
- if (!token && ((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
18
- token = req.session.jwt;
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
- req.currentUser = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrcb/cb-common",
3
- "version": "1.0.686",
3
+ "version": "1.0.688",
4
4
  "description": "Common resources between services",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",