@munlib/common 1.0.29 → 1.0.31
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.
|
@@ -1,2 +1,14 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
+
interface UserPayload {
|
|
3
|
+
id: string;
|
|
4
|
+
email: string;
|
|
5
|
+
}
|
|
6
|
+
declare global {
|
|
7
|
+
namespace Express {
|
|
8
|
+
interface Request {
|
|
9
|
+
user?: UserPayload;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
2
13
|
export declare const requireAuth: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
+
export {};
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.requireAuth = void 0;
|
|
4
7
|
var not_authorized_error_1 = require("../errors/not-authorized-error");
|
|
8
|
+
var jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
5
9
|
var requireAuth = function (req, res, next) {
|
|
6
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
12
|
+
// Si no hay un token JWT en la sesión, devolver Unauthorized
|
|
13
|
+
throw new not_authorized_error_1.NotAuthorizedError();
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
var payload = jsonwebtoken_1.default.verify(req.session.jwt, process.env.JWT_KEY);
|
|
17
|
+
req.user = payload;
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
7
20
|
throw new not_authorized_error_1.NotAuthorizedError();
|
|
8
21
|
}
|
|
9
22
|
next();
|