My Scenario is:
I want to call the logout function after let says 30 mins automatically in my app. Is this possible to achieve this? And moreover, I want to know the time of the user's last interactivity with my application. Can anybody help me regarding this??
My Scenario is:
I want to call the logout function after let says 30 mins automatically in my app. Is this possible to achieve this? And moreover, I want to know the time of the user's last interactivity with my application. Can anybody help me regarding this??
Share Improve this question edited Sep 28, 2021 at 10:56 Uvindu 294 bronze badges asked Dec 31, 2015 at 6:36 Tech KidTech Kid 5772 gold badges7 silver badges19 bronze badges 12- 2 Yes you can: developer.mozilla/en-US/docs/Web/API/WindowTimers/… – K K Commented Dec 31, 2015 at 6:38
- 2 ng-idle module can help – Grundy Commented Dec 31, 2015 at 6:39
- 1 use setInterval is the best idea i hope – Rahul Kamboj Commented Dec 31, 2015 at 6:39
-
3
@RahulKamboj,
setInteval
will call a function again and again after certain interval. If it's meant to be invoked only once, thensetTimeout
is the one. Even that won't be useful in case of Angular as that function will be executed outside AngularJS context, so I think$timeout
is the service he needs to use. – Arkantos Commented Dec 31, 2015 at 6:43 -
1
@Tech Kid, as Grundy suggested,
ng-idle
is the one that takes care of inactivity and provides callbacks to work with – Arkantos Commented Dec 31, 2015 at 6:45
2 Answers
Reset to default 9Use below for any function that requires time out. But I will not suggest this for Logout. Better you can use browser session to logout after 30 min.
$timeout(function() {
// your code
}, 3000); // 3 seconds
use setTimeout() pure javascript function that can be invoked after a time of interval
setTimeout(function(){
logout();
},5000)