src/app/guards/require-multi-factor.guard.ts
Methods |
constructor(router: Router, app: AppState)
|
canActivate |
canActivate()
|
Returns :
Observable<boolean>
|
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot
} from '@angular/router';
import { MultiFactorTypes } from '../enums/multi-factor-types';
import { AppState } 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: AppState) {}
canActivate(): Observable<boolean> {
return this.app.state$.pipe(
map(data => data.passMfa),
map(passMfa => {
if (passMfa) {
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;
})
);
}
}