src/app/providers/guards/require-multi-factor.guard.ts
Methods |
constructor(router: Router, app: AppStateStore)
|
|||||||||
Parameters :
|
canActivate |
canActivate()
|
Returns :
Observable<boolean>
|
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot,
} from '@angular/router';
import { AppStateStore } from '../stores/app-state.store';
import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators/map';
@Injectable()
export class RequireMultiFactorGuard implements CanActivate {
constructor(private router: Router, private app: AppStateStore) {}
canActivate(): Observable<boolean> {
return this.app.state$.pipe(
map((state) => {
if (!this.app.requireMfa) {
console.log('passed mfa required guard');
// mfa passed continue to payment creation
return true;
}
console.log('failed mfa required guard');
// mfa required
this.router.navigate(['/authenticate-method']);
return false;
})
);
}
}