src/app/guards/skip-secret-word.guard.ts
Methods |
constructor(router: Router, app: AppState)
|
Defined in src/app/guards/skip-secret-word.guard.ts:8
|
canActivate |
canActivate()
|
Defined in src/app/guards/skip-secret-word.guard.ts:10
|
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;
})
);
}
}