@bluemarble/bm-components 1.11.1 → 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 +13 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +13 -7
- 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,12 +4510,14 @@ 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) {
|
|
@@ -4555,12 +4559,14 @@ var AuthHelper = class {
|
|
|
4555
4559
|
});
|
|
4556
4560
|
}
|
|
4557
4561
|
if (req.url.endsWith("/me")) {
|
|
4558
|
-
decodeSessionToken({
|
|
4562
|
+
const error = decodeSessionToken({
|
|
4559
4563
|
req,
|
|
4560
4564
|
res,
|
|
4561
4565
|
sessionTokenName: this.cookies.sessionToken,
|
|
4562
4566
|
validate: true
|
|
4563
4567
|
});
|
|
4568
|
+
if (error)
|
|
4569
|
+
return;
|
|
4564
4570
|
if (!req.user)
|
|
4565
4571
|
return res.status(400).json({ error: "Usu\xE1rio n\xE3o encontrado" });
|
|
4566
4572
|
const userData = yield this.onGetUserData(req.user);
|
|
@@ -4631,7 +4637,7 @@ var AuthHelper = class {
|
|
|
4631
4637
|
const { fullName, email } = yield this.oauthSignInCallback(code);
|
|
4632
4638
|
const userExists = this.onGetUserData(email);
|
|
4633
4639
|
if (!userExists && this.oauth) {
|
|
4634
|
-
this.oauth.onCreateUser({ fullname: fullName, email });
|
|
4640
|
+
yield this.oauth.onCreateUser({ fullname: fullName, email });
|
|
4635
4641
|
}
|
|
4636
4642
|
const { token, refreshToken } = yield this.generateJwtAndRefreshToken(
|
|
4637
4643
|
email,
|