SankethBK / local_session_timeout

Redirect user to authentication page if the application doesn't receive any user interaction, or been running in the background for "x" duration.
https://pub.dev/packages/local_session_timeout
BSD 3-Clause "New" or "Revised" License
12 stars 19 forks source link

SessionTimeoutState.userInactivityTimeout event keep calling even when user is interact with the app . #15

Closed anil-softuvo1 closed 1 year ago

anil-softuvo1 commented 1 year ago

SessionTimeoutState.userInactivityTimeout event keep calling even when user is interact with the app.

I have implemented the code on home screen , when i'm on home screen and home screen is idle for 10 seconds then this works fine . but when i'm on other screen and keep interacting with the app it sends back me to pin screen . Here is my code

handleLocalSession(seconds: 10);

handleLocalSession({int? seconds}) { sessionConfig = SessionConfig( invalidateSessionForAppLostFocus: Duration(seconds: seconds!), invalidateSessionForUserInactivity: Duration(seconds: seconds));

sessionConfig.stream.listen((SessionTimeoutState timeoutEvent) {
  sessionStateStream.add(SessionState.stopListening);
  if (timeoutEvent == SessionTimeoutState.userInactivityTimeout) {
    // handle user  inactive timeout
    log("userInactivityTimeout ");
    Get.toNamed(PageRoutes.pinScreen);
  } else if (timeoutEvent == SessionTimeoutState.appFocusTimeout) {
    // handle user  app lost focus timeout
    log("appFocusTimeout  ");
    Get.toNamed(PageRoutes.pinScreen);
  }
});

}

SankethBK commented 1 year ago

Default value of userActivityDebounceDuration is 10 seconds which means it records only one user event for 10 seconds (to prevent memory leaks because of setTimeout objects), you can change this value to a lower number like 1 or 2 seconds. You can pass it as a parameter to SessionTimeoutManager