@eratu/common 1.0.12 → 1.0.14
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
|
@@ -46,3 +46,4 @@ __exportStar(require("./events/event-types/auth/author-signed-out-event"), expor
|
|
|
46
46
|
__exportStar(require("./events/event-types/orders/order-created-event"), exports);
|
|
47
47
|
__exportStar(require("./events/subjects"), exports);
|
|
48
48
|
__exportStar(require("./events/streams"), exports);
|
|
49
|
+
__exportStar(require("./nats-wrapper"), exports);
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { Request, Response, NextFunction } from "express";
|
|
2
|
-
|
|
2
|
+
import { UserRoles } from "../enum/roles";
|
|
3
|
+
export interface UserJwtPayload {
|
|
3
4
|
id: string;
|
|
4
5
|
email: string;
|
|
6
|
+
firstName: string;
|
|
7
|
+
lastName: string;
|
|
8
|
+
role: UserRoles;
|
|
9
|
+
}
|
|
10
|
+
export interface JwtPayload {
|
|
11
|
+
email: string;
|
|
12
|
+
firstName: string;
|
|
13
|
+
lastName: string;
|
|
14
|
+
role: UserRoles;
|
|
15
|
+
sub: string;
|
|
16
|
+
aud: string;
|
|
17
|
+
iss: string;
|
|
18
|
+
iat: number;
|
|
19
|
+
exp: number;
|
|
5
20
|
}
|
|
6
21
|
declare global {
|
|
7
22
|
namespace Express {
|
|
8
23
|
interface Request {
|
|
9
|
-
currentUser?:
|
|
24
|
+
currentUser?: UserJwtPayload;
|
|
10
25
|
}
|
|
11
26
|
}
|
|
12
27
|
}
|
|
13
28
|
export declare const currentUser: (req: Request, res: Response, next: NextFunction) => void;
|
|
14
|
-
export {};
|
|
@@ -6,13 +6,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.currentUser = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
8
|
const currentUser = (req, res, next) => {
|
|
9
|
-
|
|
9
|
+
var _a;
|
|
10
|
+
const token = (_a = req.headers["authorization"]) === null || _a === void 0 ? void 0 : _a.split(" ")[1];
|
|
10
11
|
if (!token) {
|
|
11
12
|
return next();
|
|
12
13
|
}
|
|
13
14
|
try {
|
|
14
15
|
const payload = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY);
|
|
15
|
-
|
|
16
|
+
const userData = {
|
|
17
|
+
id: payload.sub,
|
|
18
|
+
email: payload.email,
|
|
19
|
+
firstName: payload.firstName,
|
|
20
|
+
lastName: payload.lastName,
|
|
21
|
+
role: payload.role,
|
|
22
|
+
};
|
|
23
|
+
req.currentUser = userData;
|
|
16
24
|
}
|
|
17
25
|
catch (err) { }
|
|
18
26
|
next();
|