File

src/app/guards/skip-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 { CanActivate, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { AppState } from '../stores/app-state.store';
import { map } from 'rxjs/operators';

@Injectable()
export class SkipSecretWordGuard 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 skip secret guard');
          // skip secret word
          this.router.navigate(['payment/create']);
          return false;
        }
        console.log('failed skip secret guard');
        // continue to create secret word
        return true;
      })
    );
  }
}

results matching ""

    No results matching ""