最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular18 - @ng-idle service in angular - Stack Overflow

programmeradmin8浏览0评论

My senior created autologout function in the login component by using @ng-idle service and angular 12 3 years ago, now i upgraged angular version with angular 18 and my system is not getting automatically logout with more then 1 hours of inactivity. Can anyone help me to find either idle service is compatible with angular 18 or not This is some of my code snippet. constructor(private sharedService: SharedService, private authservice:AuthGuard, private cookieService:CookieService, public dialog: MatDialog, private loginService: LoginService, private router: Router, private fb: FormBuilder, public MatDialog: MatDialog, public forgotdialog: ForgotpassService, private idle: Idle, private keepalive: Keepalive, private sideNavService: LayoutService, private activatedRoute : ActivatedRoute ) { // this.sharedService.loadConfigData() // sets an idle timeout of 5 seconds, for testing purposes. idle.setIdle(1790); // sets a timeout period of 5 seconds. after 10 seconds of inactivity, the user will be considered timed out. idle.setTimeout(10); // sets the default interrupts, in this case, things like clicks, scrolls, touches to the document idle.setInterrupts(DEFAULT_INTERRUPTSOURCES);

idle.onIdleEnd.subscribe(() => {
  this.idleState = 'No longer idle.'
});
idle.onTimeout.subscribe(() => {
  let button
  this.idleState = 'Timed out!';
  this.timedOut = true;
  console.log('login calling----->');
  this.sideNavService.getLogoutFrom('timeout')
  this.cookieService.delete('token'),
  localStorage.removeItem('ClientfirstName');
  localStorage.removeItem('ClientlastName');
  localStorage.removeItem('clientid');
  localStorage.removeItem('role');
  localStorage.removeItem('emailaddress');
  localStorage.removeItem('token');
  localStorage.removeItem("LoginType");
  localStorage.removeItem('clientUserId');
  localStorage.removeItem("clientPartnerId")
  localStorage.removeItem("currentFeature");
  localStorage.removeItem("objectData");
  localStorage.removeItem('role');

  this.router.navigate(['/'])
  sessionStorage.clear();
});
idle.onIdleStart.subscribe(() => {
  this.idleState = 'You\'ve gone idle!'
});
idle.onTimeoutWarning.subscribe((countdown) => {
  this.idleState = 'You will time out in ' + countdown + ' seconds!'
  this.sideNavService.getLogoutMsg(countdown)
});

// sets the ping interval to 15 seconds
keepalive.interval(1);

keepalive.onPing.subscribe(() => {
  this.lastPing = new Date()
  this.sideNavService.getLogoutMsg(false)
});

I tried to get the compability of idle service with angular 18 and expacting to work seamlessly getting logout from application in 1 hours of inactivity.

发布评论

评论列表(0)

  1. 暂无评论