@bluemarble/bm-components 1.11.0 → 1.11.2
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/dist/index.js +18 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4413,8 +4413,10 @@ function decodeSessionToken({
|
|
|
4413
4413
|
}) {
|
|
4414
4414
|
var _a;
|
|
4415
4415
|
const token = ((_a = req.headers.authorization) == null ? void 0 : _a.split(" ")[1]) || req.cookies[sessionTokenName];
|
|
4416
|
-
if (!token)
|
|
4417
|
-
|
|
4416
|
+
if (!token) {
|
|
4417
|
+
res.status(401).json({ error: "Token inv\xE1lido", code: "token.invalid" });
|
|
4418
|
+
return true;
|
|
4419
|
+
}
|
|
4418
4420
|
const jwtDecode = (token2) => {
|
|
4419
4421
|
if (validate) {
|
|
4420
4422
|
return _jsonwebtoken2.default.verify(token2, process.env.JWT_SECRET);
|
|
@@ -4424,9 +4426,9 @@ function decodeSessionToken({
|
|
|
4424
4426
|
try {
|
|
4425
4427
|
const decoded = jwtDecode(token);
|
|
4426
4428
|
req.user = decoded.sub;
|
|
4427
|
-
return;
|
|
4428
4429
|
} catch (error) {
|
|
4429
|
-
|
|
4430
|
+
res.status(401).json({ error: "Token inv\xE1lido", code: "token.expired" });
|
|
4431
|
+
return true;
|
|
4430
4432
|
}
|
|
4431
4433
|
}
|
|
4432
4434
|
var AuthHelper = class {
|
|
@@ -4508,17 +4510,20 @@ var AuthHelper = class {
|
|
|
4508
4510
|
this.invalidateCookies(res).end();
|
|
4509
4511
|
}
|
|
4510
4512
|
if (req.url.endsWith("/refresh")) {
|
|
4511
|
-
decodeSessionToken({
|
|
4513
|
+
const error = decodeSessionToken({
|
|
4512
4514
|
req,
|
|
4513
4515
|
res,
|
|
4514
4516
|
sessionTokenName: this.cookies.sessionToken,
|
|
4515
4517
|
validate: false
|
|
4516
4518
|
});
|
|
4519
|
+
if (error)
|
|
4520
|
+
return;
|
|
4517
4521
|
const userId = String(req.user);
|
|
4518
4522
|
const refreshToken = _nookies.parseCookies.call(void 0, { req })[this.cookies.refreshToken];
|
|
4519
4523
|
if (!refreshToken) {
|
|
4520
|
-
|
|
4521
|
-
|
|
4524
|
+
this.invalidateCookies(res);
|
|
4525
|
+
return res.status(400).json({
|
|
4526
|
+
error: "Refresh Token inv\xE1lido"
|
|
4522
4527
|
});
|
|
4523
4528
|
}
|
|
4524
4529
|
const isValidRefreshToken = yield this.onValidateRefreshToken(
|
|
@@ -4526,7 +4531,8 @@ var AuthHelper = class {
|
|
|
4526
4531
|
refreshToken
|
|
4527
4532
|
);
|
|
4528
4533
|
if (!isValidRefreshToken) {
|
|
4529
|
-
|
|
4534
|
+
this.invalidateCookies(res);
|
|
4535
|
+
return res.status(400).json({
|
|
4530
4536
|
error: "Refresh Token inv\xE1lido"
|
|
4531
4537
|
});
|
|
4532
4538
|
}
|
|
@@ -4553,12 +4559,14 @@ var AuthHelper = class {
|
|
|
4553
4559
|
});
|
|
4554
4560
|
}
|
|
4555
4561
|
if (req.url.endsWith("/me")) {
|
|
4556
|
-
decodeSessionToken({
|
|
4562
|
+
const error = decodeSessionToken({
|
|
4557
4563
|
req,
|
|
4558
4564
|
res,
|
|
4559
4565
|
sessionTokenName: this.cookies.sessionToken,
|
|
4560
4566
|
validate: true
|
|
4561
4567
|
});
|
|
4568
|
+
if (error)
|
|
4569
|
+
return;
|
|
4562
4570
|
if (!req.user)
|
|
4563
4571
|
return res.status(400).json({ error: "Usu\xE1rio n\xE3o encontrado" });
|
|
4564
4572
|
const userData = yield this.onGetUserData(req.user);
|
|
@@ -4629,7 +4637,7 @@ var AuthHelper = class {
|
|
|
4629
4637
|
const { fullName, email } = yield this.oauthSignInCallback(code);
|
|
4630
4638
|
const userExists = this.onGetUserData(email);
|
|
4631
4639
|
if (!userExists && this.oauth) {
|
|
4632
|
-
this.oauth.onCreateUser({ fullname: fullName, email });
|
|
4640
|
+
yield this.oauth.onCreateUser({ fullname: fullName, email });
|
|
4633
4641
|
}
|
|
4634
4642
|
const { token, refreshToken } = yield this.generateJwtAndRefreshToken(
|
|
4635
4643
|
email,
|