Redirect on login page after 30 seconds of inactivity

#1

I have requirement where we need to redirect user on back to login screen if no activity on till 30 seconds.

Please help how to do it.

#2

“Activity” needs to be defined in more detail.

#3

I mean lets consider user is on dashboard screen and user don’t touch screen for 30 sec or don’t do any activity with in app so after 30 sec it should auto logout user and display login screen back.

#4

It sounds to me like your concept of “login” is completely device-contained. If so, it’s meaningless. If I’m wrong, and there is a backend that handles authentication, what you could do is use the iat claim of a JWT to do expiry on the server side, although 30 seconds seems like a ludicrously short leash to me.

#5

I think you are getting my concern, I am working on loyalty app which is deployed on store tablet and customer can check there points. customer login using phone number and can see points only thats simple functionality but it may be case that customer don’t logout out of tablet and leave it as it is. So for safe side we want to auto change of screen after 30 seconds if screen it idle.

#6

I suppose after that idle timeout is hit, you can logout of the session and redirect the local app to its login screen. There is a module that detects idle timeout and has been referred to in the past here, called ng2-idle. I’ve never used it, but for whatever reason, that repo has “HackedByChinese” in it, so I’m not linking to it. Google for it.

Edit: It seems “HackedByChinese” is intentional and the author’s idea of a joke, but google anyway.

#7

I see no need to store any credentials on the device for this. You send the phone number to the backend, it responds with the number of points. Device displays “you have 670 points”.

Then it is displaying “you have 670 points”, with no other context. I see no cause for concern.

I still think you are overengineering this, but you can use the RxJS timer operator and cancel/restart the timer on each action you consider “activity”.