strapi-plugin-magic-sessionmanager 4.0.0 → 4.0.1

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.
Files changed (33) hide show
  1. package/admin/src/components/LicenseGuard.jsx +6 -6
  2. package/admin/src/components/SessionDetailModal.jsx +12 -12
  3. package/admin/src/components/SessionInfoCard.jsx +3 -3
  4. package/admin/src/components/SessionInfoPanel.jsx +3 -2
  5. package/admin/src/pages/Analytics.jsx +2 -2
  6. package/admin/src/pages/HomePage.jsx +11 -14
  7. package/admin/src/pages/License.jsx +2 -2
  8. package/admin/src/pages/Settings.jsx +24 -24
  9. package/admin/src/pages/SettingsNew.jsx +21 -21
  10. package/admin/src/utils/parseUserAgent.js +6 -6
  11. package/dist/_chunks/{Analytics-ioaeEh-E.js → Analytics-BBdv1I5y.js} +4 -4
  12. package/dist/_chunks/{Analytics-mYu_uGwU.mjs → Analytics-Dv9f_0eZ.mjs} +4 -4
  13. package/dist/_chunks/{App-BXpIS12l.mjs → App-CIQ-7sa7.mjs} +26 -31
  14. package/dist/_chunks/{App-DdnUYWbC.js → App-CJaZPNjt.js} +26 -31
  15. package/dist/_chunks/{License-DZYrOgcx.js → License-D24rgaZQ.js} +3 -3
  16. package/dist/_chunks/{License-C03C2j9P.mjs → License-nrmFxoBm.mjs} +3 -3
  17. package/dist/_chunks/{Settings-C6_CqpCC.js → Settings-CqxgjU0y.js} +26 -26
  18. package/dist/_chunks/{Settings-0ocB3qHk.mjs → Settings-D5dLEGc_.mjs} +26 -26
  19. package/dist/_chunks/{index-DBRS3kt5.mjs → index-Duk1_Wrz.mjs} +12 -12
  20. package/dist/_chunks/{index-DC8Y0qxx.js → index-WH04CS1c.js} +12 -12
  21. package/dist/_chunks/{useLicense-qgGfMvse.js → useLicense-BwOlCyhc.js} +1 -1
  22. package/dist/_chunks/{useLicense-DSLL9n3Y.mjs → useLicense-Ce8GaxB0.mjs} +1 -1
  23. package/dist/admin/index.js +1 -1
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/server/index.js +142 -33
  26. package/dist/server/index.mjs +142 -33
  27. package/package.json +1 -1
  28. package/server/src/bootstrap.js +76 -4
  29. package/server/src/controllers/session.js +59 -9
  30. package/server/src/middlewares/last-seen.js +5 -4
  31. package/server/src/routes/content-api.js +11 -2
  32. package/server/src/services/notifications.js +10 -10
  33. package/server/src/services/session.js +24 -4
@@ -37,12 +37,12 @@ module.exports = ({ strapi }) => ({
37
37
  strapi.log.debug('[magic-sessionmanager/notifications] Using default fallback templates');
38
38
  return {
39
39
  suspiciousLogin: {
40
- subject: '🚨 Suspicious Login Alert - Session Manager',
40
+ subject: '[ALERT] Suspicious Login Alert - Session Manager',
41
41
  html: `
42
42
  <html>
43
43
  <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
44
44
  <div style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #f9fafb; border-radius: 10px;">
45
- <h2 style="color: #dc2626;">🚨 Suspicious Login Detected</h2>
45
+ <h2 style="color: #dc2626;">[ALERT] Suspicious Login Detected</h2>
46
46
  <p>A potentially suspicious login was detected for your account.</p>
47
47
 
48
48
  <div style="background: white; padding: 15px; border-radius: 8px; margin: 20px 0;">
@@ -77,7 +77,7 @@ module.exports = ({ strapi }) => ({
77
77
  </div>
78
78
  </body>
79
79
  </html>`,
80
- text: `🚨 Suspicious Login Detected\n\nA potentially suspicious login was detected for your account.\n\nAccount: {{user.email}}\nUsername: {{user.username}}\n\nLogin Details:\n- Time: {{session.loginTime}}\n- IP: {{session.ipAddress}}\n- Location: {{geo.city}}, {{geo.country}}\n\nSecurity: VPN={{reason.isVpn}}, Proxy={{reason.isProxy}}, Threat={{reason.isThreat}}, Score={{reason.securityScore}}/100`,
80
+ text: `[ALERT] Suspicious Login Detected\n\nA potentially suspicious login was detected for your account.\n\nAccount: {{user.email}}\nUsername: {{user.username}}\n\nLogin Details:\n- Time: {{session.loginTime}}\n- IP: {{session.ipAddress}}\n- Location: {{geo.city}}, {{geo.country}}\n\nSecurity: VPN={{reason.isVpn}}, Proxy={{reason.isProxy}}, Threat={{reason.isThreat}}, Score={{reason.securityScore}}/100`,
81
81
  },
82
82
  newLocation: {
83
83
  subject: '[LOCATION] New Location Login Detected',
@@ -262,9 +262,9 @@ module.exports = ({ strapi }) => ({
262
262
  title: this.getEventTitle(event),
263
263
  color: this.getEventColor(event),
264
264
  fields: [
265
- { name: '👤 User', value: `${user.email}\n${user.username || 'N/A'}`, inline: true },
266
- { name: '🌐 IP', value: session.ipAddress, inline: true },
267
- { name: '📅 Time', value: new Date(session.loginTime).toLocaleString(), inline: false },
265
+ { name: 'User', value: `${user.email}\n${user.username || 'N/A'}`, inline: true },
266
+ { name: 'IP', value: session.ipAddress, inline: true },
267
+ { name: 'Time', value: new Date(session.loginTime).toLocaleString(), inline: false },
268
268
  ],
269
269
  timestamp: new Date().toISOString(),
270
270
  footer: { text: 'Magic Session Manager' },
@@ -296,11 +296,11 @@ module.exports = ({ strapi }) => ({
296
296
 
297
297
  getEventTitle(event) {
298
298
  const titles = {
299
- 'login.suspicious': '🚨 Suspicious Login',
299
+ 'login.suspicious': '[ALERT] Suspicious Login',
300
300
  'login.new_location': '[LOCATION] New Location Login',
301
- 'login.vpn': '🔴 VPN Login Detected',
302
- 'login.threat': ' Threat IP Login',
303
- 'session.terminated': '🔴 Session Terminated',
301
+ 'login.vpn': '[WARNING] VPN Login Detected',
302
+ 'login.threat': '[THREAT] Threat IP Login',
303
+ 'session.terminated': '[INFO] Session Terminated',
304
304
  };
305
305
  return titles[event] || '[STATS] Session Event';
306
306
  },
@@ -63,6 +63,7 @@ module.exports = ({ strapi }) => ({
63
63
 
64
64
  /**
65
65
  * Terminate a session or all sessions for a user
66
+ * Supports both numeric id (legacy) and documentId (Strapi v5)
66
67
  * @param {Object} params - { sessionId | userId }
67
68
  * @returns {Promise<void>}
68
69
  */
@@ -82,10 +83,19 @@ module.exports = ({ strapi }) => ({
82
83
 
83
84
  strapi.log.info(`[magic-sessionmanager] Session ${sessionId} terminated`);
84
85
  } else if (userId) {
86
+ // Strapi v5: If numeric id provided, look up documentId first
87
+ let userDocumentId = userId;
88
+ if (!isNaN(userId)) {
89
+ const user = await strapi.entityService.findOne(USER_UID, parseInt(userId, 10));
90
+ if (user) {
91
+ userDocumentId = user.documentId;
92
+ }
93
+ }
94
+
85
95
  // Find all active sessions for user - use Deep Filtering (Strapi v5)
86
96
  const activeSessions = await strapi.documents(SESSION_UID).findMany({
87
97
  filters: {
88
- user: { documentId: userId }, // Deep filtering syntax
98
+ user: { documentId: userDocumentId }, // Deep filtering syntax
89
99
  isActive: true,
90
100
  },
91
101
  });
@@ -101,7 +111,7 @@ module.exports = ({ strapi }) => ({
101
111
  });
102
112
  }
103
113
 
104
- strapi.log.info(`[magic-sessionmanager] All sessions terminated for user ${userId}`);
114
+ strapi.log.info(`[magic-sessionmanager] All sessions terminated for user ${userDocumentId}`);
105
115
  }
106
116
  } catch (err) {
107
117
  strapi.log.error('[magic-sessionmanager] Error terminating session:', err);
@@ -196,13 +206,23 @@ module.exports = ({ strapi }) => ({
196
206
 
197
207
  /**
198
208
  * Get all sessions for a specific user
199
- * @param {number} userId
209
+ * Supports both numeric id (legacy) and documentId (Strapi v5)
210
+ * @param {string|number} userId - User documentId or numeric id
200
211
  * @returns {Promise<Array>} User's sessions with accurate online status
201
212
  */
202
213
  async getUserSessions(userId) {
203
214
  try {
215
+ // Strapi v5: If numeric id provided, look up documentId first
216
+ let userDocumentId = userId;
217
+ if (!isNaN(userId)) {
218
+ const user = await strapi.entityService.findOne(USER_UID, parseInt(userId, 10));
219
+ if (user) {
220
+ userDocumentId = user.documentId;
221
+ }
222
+ }
223
+
204
224
  const sessions = await strapi.documents(SESSION_UID).findMany( {
205
- filters: { user: { documentId: userId } },
225
+ filters: { user: { documentId: userDocumentId } },
206
226
  sort: { loginTime: 'desc' },
207
227
  });
208
228