Package not found. Please check the package name and try again.
@hastehaul/common 2.0.32 → 2.0.33
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.
|
@@ -44,33 +44,28 @@ const jsonwebtoken_1 = __importStar(require("jsonwebtoken"));
|
|
|
44
44
|
* @returns {Promise<void>} - A Promise that resolves once the user extraction is complete, but it is not used directly.
|
|
45
45
|
*/
|
|
46
46
|
const currentUser = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
|
|
47
|
+
req.currentUser = null;
|
|
48
|
+
const bearerToken = req.headers.authorization;
|
|
49
|
+
if (!bearerToken) {
|
|
50
|
+
return next();
|
|
51
|
+
}
|
|
48
52
|
try {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (token) {
|
|
54
|
-
// Verify the JWT token and decode the user payload.
|
|
55
|
-
result = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY.split("-").join(""));
|
|
56
|
-
}
|
|
53
|
+
const token = bearerToken.split(' ')[1];
|
|
54
|
+
if (token) {
|
|
55
|
+
const result = jsonwebtoken_1.default.verify(token, process.env.JWT_KEY.split('-').join(''));
|
|
56
|
+
req.currentUser = result;
|
|
57
57
|
}
|
|
58
|
-
// Attach the user payload to the request object for later use in the application.
|
|
59
|
-
req.currentUser = result;
|
|
60
58
|
}
|
|
61
59
|
catch (err) {
|
|
62
|
-
// Handle errors related to token verification or expiration.
|
|
63
60
|
if (err instanceof jsonwebtoken_1.TokenExpiredError) {
|
|
64
61
|
// If the token is expired, you may consider refreshing the token or taking appropriate actions.
|
|
65
62
|
// Uncomment the following line if you want to handle token expiration using the AuthController.
|
|
66
63
|
// await AuthController.refreshToken(req, res);
|
|
67
64
|
}
|
|
68
65
|
else {
|
|
69
|
-
|
|
70
|
-
req.currentUser = null;
|
|
66
|
+
console.error('Error verifying token:', err);
|
|
71
67
|
}
|
|
72
68
|
}
|
|
73
|
-
// Call the next middleware in the chain.
|
|
74
69
|
next();
|
|
75
70
|
});
|
|
76
71
|
exports.currentUser = currentUser;
|