aloux-iam 0.0.89 → 0.0.90
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/lib/middleware.js +16 -5
- package/package.json +1 -1
package/lib/middleware.js
CHANGED
|
@@ -65,15 +65,26 @@ const auth = async (req, res, next) => {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
//Time session
|
|
68
|
-
if(process.env.SESSION_INTERRUPTOR === "true"){
|
|
69
|
-
const userTokens = await User.findOne(
|
|
70
|
-
|
|
68
|
+
if (process.env.SESSION_INTERRUPTOR === "true") {
|
|
69
|
+
const userTokens = await User.findOne(
|
|
70
|
+
{ _id: user._id, status: "Activo" },
|
|
71
|
+
{ tokens: 1 }
|
|
72
|
+
).lean();
|
|
73
|
+
const tokenObject = userTokens.tokens.find((t) => t.token === token);
|
|
71
74
|
if (tokenObject.dateEnd <= Date.now()) {
|
|
75
|
+
await User.updateOne(
|
|
76
|
+
{ _id: userTokens._id },
|
|
77
|
+
{
|
|
78
|
+
$pull: {
|
|
79
|
+
tokens: { token: tokenObject.tokens.token }, // Condición para eliminar el token específico
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
);
|
|
72
83
|
throw {
|
|
73
|
-
code:
|
|
84
|
+
code: 401,
|
|
74
85
|
title: "La sesión expiró",
|
|
75
86
|
detail: "Has llegado al tiempo límite de tu sesión",
|
|
76
|
-
suggestion: "
|
|
87
|
+
suggestion: "Se eliminó la sesión vencida",
|
|
77
88
|
error: new Error(),
|
|
78
89
|
};
|
|
79
90
|
}
|