1- import { Component , OnInit } from '@angular/core' ;
1+ import { Component , OnDestroy , OnInit } from '@angular/core' ;
22import { DomSanitizer } from '@angular/platform-browser' ;
33import { Router } from '@angular/router' ;
44import { NgxSpinnerService } from 'ngx-spinner' ;
5- import { Observable } from 'rxjs' ;
5+ import { interval , Observable , Subscription } from 'rxjs' ;
6+ import { AccountService } from '../../../../core/auth/account.service' ;
67import { AuthServerProvider } from '../../../../core/auth/auth-jwt.service' ;
8+ import { StateStorageService } from '../../../../core/auth/state-storage.service' ;
9+ import { UtmToastService } from '../../../alert/utm-toast.service' ;
710import { ThemeChangeBehavior } from '../../../behaviors/theme-change.behavior' ;
11+ import { ADMIN_DEFAULT_EMAIL , ADMIN_ROLE } from '../../../constants/global.constant' ;
812import { TfaMethod } from '../../../services/tfa/tfa.service' ;
9- import { extractQueryParamsForNavigation } from "../../../util/query-params-to-filter.util" ;
10- import { ADMIN_DEFAULT_EMAIL , ADMIN_ROLE } from "../../../constants/global.constant" ;
11- import { StateStorageService } from "../../../../core/auth/state-storage.service" ;
12- import { AccountService } from "../../../../core/auth/account.service" ;
13- import { UtmToastService } from "../../../alert/utm-toast.service" ;
13+ import { extractQueryParamsForNavigation } from '../../../util/query-params-to-filter.util' ;
1414
1515
1616@Component ( {
1717 selector : 'app-totp' ,
1818 templateUrl : './totp.component.html' ,
1919 styleUrls : [ './totp.component.scss' ]
2020} )
21- export class TotpComponent implements OnInit {
21+ export class TotpComponent implements OnInit , OnDestroy {
2222 form : any = { } ;
23- isLoggedIn = false ;
24- isLoginFailed = false ;
2523 errorMessage = '' ;
26- currentUser : any ;
2724 isVerifying = false ;
2825 loginImage$ : Observable < string > ;
2926 TfaMethod = TfaMethod ;
3027 method : TfaMethod ;
3128 isVerified = false ;
3229 verificationCode = '' ;
30+ private expireSub : Subscription ;
3331
3432 constructor ( private authService : AuthServerProvider ,
3533 private router : Router ,
@@ -44,6 +42,8 @@ export class TotpComponent implements OnInit {
4442 ngOnInit ( ) : void {
4543 this . method = this . authService . tfaMethod ;
4644 this . loginImage$ = this . themeChangeBehavior . $themeIcon . asObservable ( ) ;
45+
46+ this . expireSub = interval ( 30 * 1000 ) . subscribe ( ( ) => this . onExpire ( ) ) ;
4747 }
4848
4949
@@ -66,7 +66,8 @@ export class TotpComponent implements OnInit {
6666 }
6767
6868 onExpire ( ) {
69-
69+ console . log ( 'expired' ) ;
70+ this . authService . renewCode ( ) . subscribe ( ) ;
7071 }
7172
7273 clearError ( ) {
@@ -94,4 +95,8 @@ export class TotpComponent implements OnInit {
9495 }
9596 } ) ;
9697 }
98+
99+ ngOnDestroy ( ) {
100+ this . expireSub . unsubscribe ( ) ;
101+ }
97102}
0 commit comments