File

src/app/guards/require-multi-factor.guard.ts

Index

Methods

Constructor

constructor(router: Router, app: AppState)
Parameters :
Name Type Optional
router Router no
app AppState no

Methods

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;
      })
    );
  }
}

results matching ""

    No results matching ""