-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to handle this after the user login #108
Comments
What I did is put ng2Idle in a service. This service does all the preliminary setup (for example, assigning setIdle/setTimeout/etc. and subscribing to the onIdleStart/onIdleEnd/etc) in its constructor. The service also has public startIdleSvc, stopIdleSvc, and isServiceRunning functions. Then, in my app.module.ts, I subscribe to the router.events observable and filter out only the RouterEvents. Then, in the subscribe, I check if the user is logged in. If the user is logged in and the idle service hasn't been started already (checking by calling the service's isServiceRunning), I start the idle service. If the user isn't logged in, and the idle service is still running (ie the user logs out on his own), I call the stopUserService function. The reason I do the router check and not start the service just when the user logs in is because the user can manually reload the page, and when that happens the user is still logged in, but the idle service has been stopped. With the router checks, this scenario is taken care of. There may be better ways to do this so if someone knows of one, please comment. Here is part of my app.module.ts:
A derivative of my idle.service.ts:
|
Hi,
I Want to Apply ng2-idle after the user login. is it possible to apply ng2-idle with conditions.
If at all user is not logged in then set the time to infinite.
Help me to solve the issue.
Thanks in advance.
The text was updated successfully, but these errors were encountered: