You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 1. If user has inactive sessions = they were explicitly logged out → BLOCK (if strict)
660
-
// 2. If user has NO sessions at all = session never created (bug/race condition) → ALLOW
661
-
// 3. If strictMode is off → always ALLOW but log warning
659
+
// 1. User has inactive sessions = explicitly logged out → ALWAYS BLOCK
660
+
// 2. No sessions exist at all = session never created (bug/race condition) → ALLOW
661
+
// 3. strictMode controls whether missing sessions block or just warn
662
662
663
-
if(!strictMode){
664
-
// Non-strict mode: Log warning but allow through
665
-
if(totalSessions===0){
666
-
strapi.log.warn(
667
-
`[magic-sessionmanager] [JWT-WARN] No session found for user ${userDocId.substring(0,8)}... (allowing - session may not have been created)`
668
-
);
669
-
}elseif(hasInactiveSessions){
670
-
strapi.log.warn(
671
-
`[magic-sessionmanager] [JWT-WARN] User ${userDocId.substring(0,8)}... has ${totalSessions} inactive sessions but no active ones (allowing - strictMode off)`
672
-
);
673
-
}
674
-
returndecoded;// Allow through in non-strict mode
663
+
if(hasInactiveSessions){
664
+
// User was explicitly logged out → ALWAYS BLOCK (this is intentional!)
665
+
strapi.log.info(
666
+
`[magic-sessionmanager] [JWT-BLOCKED] User ${userDocId.substring(0,8)}... was logged out (${totalSessions} inactive sessions)`
667
+
);
668
+
returnnull;// Block - user was explicitly logged out
675
669
}
676
670
677
-
// Strict mode enabled - more careful about blocking
671
+
// No sessions exist at all - session was never created (bug/race condition)
678
672
if(totalSessions===0){
679
-
// No sessions at all - likely a bug or race condition, allow through
673
+
if(strictMode){
674
+
// Strict mode: Block even if no sessions (could be security risk)
675
+
strapi.log.info(
676
+
`[magic-sessionmanager] [JWT-BLOCKED] No sessions exist for user ${userDocId.substring(0,8)}... (strictMode enabled)`
677
+
);
678
+
returnnull;
679
+
}
680
+
// Non-strict mode: Allow through but warn
680
681
strapi.log.warn(
681
-
`[magic-sessionmanager] [JWT-ALLOW] No sessions exist for user ${userDocId.substring(0,8)}... (allowing - possible race condition)`
682
+
`[magic-sessionmanager] [JWT-WARN] No session found for user ${userDocId.substring(0,8)}... (allowing - session may not have been created)`
682
683
);
683
684
returndecoded;
684
685
}
685
686
686
-
if(hasInactiveSessions){
687
-
// User has inactive sessions = explicitly logged out → BLOCK
688
-
strapi.log.info(
689
-
`[magic-sessionmanager] [JWT-BLOCKED] User ${userDocId.substring(0,8)}... was logged out (${totalSessions} inactive sessions)`
690
-
);
691
-
returnnull;// Block - user was explicitly logged out
692
-
}
693
-
694
687
// Edge case: sessions exist but none are active or inactive (shouldn't happen)
695
688
strapi.log.warn(
696
689
`[magic-sessionmanager] [JWT-ALLOW] Unexpected session state for user ${userDocId.substring(0,8)}... (allowing)`
0 commit comments