@tabletennisshop/common 1.0.67 → 1.0.69
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.
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BadRequestError = void 0;
|
|
4
|
+
const custom_error_1 = require("./custom-error");
|
|
5
|
+
class BadRequestError extends custom_error_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.statusCode = 400;
|
|
10
|
+
Object.setPrototypeOf(this, BadRequestError.prototype);
|
|
11
|
+
}
|
|
12
|
+
serializeErrors() {
|
|
13
|
+
return [{ message: this.message }];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.BadRequestError = BadRequestError;
|
package/build/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './errors/custom-error';
|
|
|
2
2
|
export * from './errors/not-authorized-error';
|
|
3
3
|
export * from './errors/not-found-error';
|
|
4
4
|
export * from './errors/request-validate-error';
|
|
5
|
+
export * from './errors/bad-request-error';
|
|
5
6
|
export * from './middlewares/check-authorized-middleware';
|
|
6
7
|
export * from './middlewares/error-handler';
|
|
7
8
|
export * from './middlewares/validate-request-middleware';
|
package/build/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./errors/custom-error"), exports);
|
|
|
18
18
|
__exportStar(require("./errors/not-authorized-error"), exports);
|
|
19
19
|
__exportStar(require("./errors/not-found-error"), exports);
|
|
20
20
|
__exportStar(require("./errors/request-validate-error"), exports);
|
|
21
|
+
__exportStar(require("./errors/bad-request-error"), exports);
|
|
21
22
|
__exportStar(require("./middlewares/check-authorized-middleware"), exports);
|
|
22
23
|
__exportStar(require("./middlewares/error-handler"), exports);
|
|
23
24
|
__exportStar(require("./middlewares/validate-request-middleware"), exports);
|
|
@@ -5,20 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CurrentUserMiddleware = void 0;
|
|
7
7
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
/*
|
|
9
|
+
When a user logs in, a JWT is created and stored "id" and "email" in the session.
|
|
10
|
+
So to verify the user, we need to decode the JWT.
|
|
11
|
+
This code try to verify and decode jwt to {id: "", email: ""}
|
|
12
|
+
and save it into req.currentUser.
|
|
13
|
+
Finally req.currentUser back to client.
|
|
14
|
+
*/
|
|
8
15
|
const CurrentUserMiddleware = (req, res, next) => {
|
|
9
16
|
var _a, _b;
|
|
10
17
|
if (!((_a = req.session) === null || _a === void 0 ? void 0 : _a.jwt)) {
|
|
11
18
|
next();
|
|
12
19
|
}
|
|
13
|
-
/*
|
|
14
|
-
When a user logs in, a JWT is created and stored "id" and "email" in the session.
|
|
15
|
-
So to verify the user, we need to decode the JWT.
|
|
16
|
-
This code try to verify and decode jwt to {id: "", email: ""}
|
|
17
|
-
and save it into req.currentUser.
|
|
18
|
-
Finally req.currentUser back to client.
|
|
19
|
-
*/
|
|
20
20
|
try {
|
|
21
|
-
const payload = jsonwebtoken_1.default.verify((_b = req.session) === null || _b === void 0 ? void 0 : _b.jwt,
|
|
21
|
+
const payload = jsonwebtoken_1.default.verify((_b = req.session) === null || _b === void 0 ? void 0 : _b.jwt, process.env.JWT_KEY);
|
|
22
22
|
req.currentUser = payload;
|
|
23
23
|
}
|
|
24
24
|
catch (err) {
|