File

src/app/guards/require-secret-word.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 { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators/map';
import { AppState } from '../stores/app-state.store';

@Injectable()
export class RequireSecretWordGuard implements CanActivate {
  constructor(private router: Router, private app: AppState) {}
  canActivate(): Observable<boolean> {
    return this.app.state$.pipe(
      map((state) => {
        if (state.isSecretValid) {
          console.log('passed secret required guard');
          // secret word passed continue to payment creation
          return true;
        }
        console.log('failed secret required guard');
        // secret word required
        this.router.navigate(['/creating-sw']);
        return false;
      })
    );
  }
}

results matching ""

    No results matching ""