@@ -95,48 +95,59 @@ export class SessionMonitor {
95
95
}
96
96
97
97
updateSession ( ) {
98
- if ( SessionMonitor . isUserOnPage ( 'login' ) || this . logoutPopupShown ) {
99
- return Promise . resolve ( 0 ) ;
98
+ const afterUserCheck = ( ) => {
99
+ const timeSinceLastActivity = Date . now ( ) - this . mostRecentActivityTimestamp ;
100
+ // If user has been inactive for Y min, and they are not in a workspace
101
+ if ( timeSinceLastActivity >= this . inactiveTimeLimit
102
+ && ! SessionMonitor . isUserOnPage ( 'workspace' )
103
+ && logoutInactiveUsers ) {
104
+ this . logoutUser ( ) ;
105
+ return Promise . resolve ( 0 ) ;
106
+ }
107
+
108
+ // If the user has been inactive for this.inactiveWorkspaceTimeLimit minutes
109
+ // and they *are* in a workspace
110
+ if ( timeSinceLastActivity >= this . inactiveWorkspaceTimeLimit
111
+ && SessionMonitor . isUserOnPage ( 'workspace' )
112
+ && logoutInactiveUsers ) {
113
+ this . logoutUser ( ) ;
114
+ return Promise . resolve ( 0 ) ;
115
+ }
116
+
117
+ // If user has been inactive for Y min, and they are not in a workspace
118
+ // trigger warning popup
119
+ if ( timeSinceLastActivity >= ( this . inactiveTimeLimit - this . inactiveWarningTime )
120
+ && ! SessionMonitor . isUserOnPage ( 'workspace' )
121
+ && logoutInactiveUsers ) {
122
+ this . warnUser ( this . mostRecentActivityTimestamp + this . inactiveTimeLimit ) ;
123
+ return Promise . resolve ( 0 ) ;
124
+ }
125
+
126
+ // If the user has been inactive for this.inactiveWorkspaceTimeLimit minutes
127
+ // and they *are* in a workspace
128
+ // trigger warning popup
129
+ if ( timeSinceLastActivity >= ( this . inactiveWorkspaceTimeLimit - this . inactiveWarningTime )
130
+ && SessionMonitor . isUserOnPage ( 'workspace' )
131
+ && logoutInactiveUsers ) {
132
+ this . warnUser ( this . mostRecentActivityTimestamp + this . inactiveWorkspaceTimeLimit ) ;
133
+ return Promise . resolve ( 0 ) ;
134
+ }
135
+
136
+ return this . refreshSession ( ) ;
100
137
}
101
138
102
- const timeSinceLastActivity = Date . now ( ) - this . mostRecentActivityTimestamp ;
103
- // If user has been inactive for Y min, and they are not in a workspace
104
- if ( timeSinceLastActivity >= this . inactiveTimeLimit
105
- && ! SessionMonitor . isUserOnPage ( 'workspace' )
106
- && logoutInactiveUsers ) {
107
- this . logoutUser ( ) ;
108
- return Promise . resolve ( 0 ) ;
109
- }
110
-
111
- // If the user has been inactive for this.inactiveWorkspaceTimeLimit minutes
112
- // and they *are* in a workspace
113
- if ( timeSinceLastActivity >= this . inactiveWorkspaceTimeLimit
114
- && SessionMonitor . isUserOnPage ( 'workspace' )
115
- && logoutInactiveUsers ) {
116
- this . logoutUser ( ) ;
117
- return Promise . resolve ( 0 ) ;
118
- }
119
-
120
- // If user has been inactive for Y min, and they are not in a workspace
121
- // trigger warning popup
122
- if ( timeSinceLastActivity >= ( this . inactiveTimeLimit - this . inactiveWarningTime )
123
- && ! SessionMonitor . isUserOnPage ( 'workspace' )
124
- && logoutInactiveUsers ) {
125
- this . warnUser ( this . mostRecentActivityTimestamp + this . inactiveTimeLimit ) ;
139
+ if ( SessionMonitor . isUserOnPage ( 'login' ) || this . logoutPopupShown ) {
126
140
return Promise . resolve ( 0 ) ;
127
141
}
128
142
129
- // If the user has been inactive for this.inactiveWorkspaceTimeLimit minutes
130
- // and they *are* in a workspace
131
- // trigger warning popup
132
- if ( timeSinceLastActivity >= ( this . inactiveWorkspaceTimeLimit - this . inactiveWarningTime )
133
- && SessionMonitor . isUserOnPage ( 'workspace' )
134
- && logoutInactiveUsers ) {
135
- this . warnUser ( this . mostRecentActivityTimestamp + this . inactiveWorkspaceTimeLimit ) ;
136
- return Promise . resolve ( 0 ) ;
137
- }
143
+ // check if user is logged in for logout warnings
144
+ return getReduxStore ( ) . then ( ( store ) => {
145
+ if ( ! store ?. getState ( ) ?. user ?. username ) {
146
+ return Promise . resolve ( 0 ) ;
147
+ }
148
+ return afterUserCheck ( ) ;
149
+ } ) ;
138
150
139
- return this . refreshSession ( ) ;
140
151
}
141
152
142
153
refreshSession ( ) {
0 commit comments