Javascript 用户空闲服务问题
我正在为angular使用用户空闲服务()。我在angular 6前端应用程序中使用它,但遇到了一些问题,即当我的用户处于活动状态时,他们会过早地被开除 用户登录到应用程序后,我立即启动库。它在大多数情况下都能工作,但有时用户在浏览器中处于活动状态时会被过早地踢出。我仅将其用于基于浏览器的用途 在我的服务类中,我触发了下面的命令,以及下面的配置。图书馆里有什么东西我用错了吗Javascript 用户空闲服务问题,javascript,angular,typescript,angular6,Javascript,Angular,Typescript,Angular6,我正在为angular使用用户空闲服务()。我在angular 6前端应用程序中使用它,但遇到了一些问题,即当我的用户处于活动状态时,他们会过早地被开除 用户登录到应用程序后,我立即启动库。它在大多数情况下都能工作,但有时用户在浏览器中处于活动状态时会被过早地踢出。我仅将其用于基于浏览器的用途 在我的服务类中,我触发了下面的命令,以及下面的配置。图书馆里有什么东西我用错了吗 constructor(private http: Http, private router: R
constructor(private http: Http,
private router: Router,
private cookieService: CookieService,
private userIdle: UserIdleService) {
this.userIdle.setCustomActivityEvents(merge(
fromEvent(window, 'mousemove'),
fromEvent(window, 'resize'),
fromEvent(document, 'keydown'),
fromEvent(document, 'touchstart'),
fromEvent(document, 'touchend'),
fromEvent(window, 'scroll')
));
}
login(credentials: Credentials): Observable<any> {
return this.http.post<any>(this.loginUrl, JSON.stringify(credentials), {
headers: new HttpHeaders({'Content-Type': 'application/json'})
})
.pipe(map(userDetails => {
this.setUserDetailsAndExtendExpirationInLocalStorage(userDetails);
this.startUserIdle();
this.goToHome();
}));
}
startUserIdle() {
this.userIdle.startWatching();
this.subscriptions.push((this.userIdle.onTimerStart().subscribe()));
this.subscriptions.push((this.userIdle.onTimeout().subscribe(() => {
this.logout();
})));
this.subscriptions.push(this.userIdle.ping$.subscribe(() => {
this.refreshToken();
}));
}
refreshToken() {
return this.http.get<any>(this.refreshUrl, {
headers: new HttpHeaders({'Content-Type': 'application/json'})
}).subscribe(() => {
// do stuff
}, () => {
this.logout();
});
}
logout() {
this.goToLogin();
this.removeUserDetails();
this.removeSessionToken();
this.userIdle.resetTimer();
this.userIdle.stopTimer();
this.userIdle.stopWatching();
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.setIsLoggedIn(false);
}
我建议您使用这个npm,我创建它也是为了同样的需要。它在@BearNithi下工作得很好这只有一个超时值,不是空闲值,对吗?因此,我认为这并不是一个真正的替代方法。您能确保在执行
this.logout()时出错吗代码>的理由正确吗?您是在刷新令牌到期之前及时刷新,还是这一时间已经超过了到期时间?
UserIdleModule.forRoot({idle: 900, timeout: 1, ping: 840})