Skip to content
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

Fix timout issue #449

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { IAuthUserProfile } from 'src/app/shared/models/user/auth-user-profile.i
import { ProfileService } from '../services/profile/profile.service'

const TIME_BEFORE_START_IDLE = 1
const TIME_TO_WAIT_IDLE = 3600
const TIME_TO_WAIT_IDLE = 120

@Injectable({
providedIn: 'root',
Expand All @@ -48,7 +48,11 @@ export class AuthService {
private router: Router,
public idle: Idle,
private keepAlive: Keepalive
) {}
) {
if (this.isLoggedIn) {
this.initIdle()
}
}

public initTokenHandling(): void {
if (this.oauthService.state) {
Expand All @@ -67,11 +71,10 @@ export class AuthService {
this.idle.setIdle(TIME_BEFORE_START_IDLE)
this.idle.setTimeout(TIME_TO_WAIT_IDLE)
this.idle.setInterrupts(DEFAULT_INTERRUPTSOURCES)

this.idle.onIdleEnd.subscribe(() => {
console.log('IDLE RESTARTED')
this.resetIdle()
})

this.idle.onTimeout.subscribe(() => {
this.timedOut = true
this.logout()
Expand Down Expand Up @@ -128,14 +131,19 @@ export class AuthService {
}

if (this.userInfo.sub !== userInfo?.info?.sub) {
await this.createUser(userInfo.info.sub).toPromise()
await this.createUser(userInfo.info.sub)
.toPromise()
.finally(() => {
if (!this.idle.isIdling()) {
this.initIdle()
}
})
}

this.userInfo = userInfo.info
this.userInfoSubject$.next(this.userInfo)

this.profileService.get().subscribe()
this.initIdle()
}

private clearUserInfo(): void {
Expand Down