src/app/guards/limits.guard.ts
Methods |
constructor(app: AppState, errorStore: ErrorStore, router: Router)
|
||||||||||||
Defined in src/app/guards/limits.guard.ts:8
|
||||||||||||
Parameters :
|
canActivate |
canActivate()
|
Defined in src/app/guards/limits.guard.ts:11
|
Returns :
any
|
import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import { filter, map } from 'rxjs/operators';
import { AppState } from '../stores/app-state.store';
import { ErrorStore } from '../stores/error.store';
@Injectable()
export class LimitsGuard implements CanActivate {
constructor(private app: AppState, private errorStore: ErrorStore, private router: Router) {}
canActivate() {
return this.app.state$.pipe(
filter(state => state !== null && state !== undefined),
map(state => {
if (!state.limitsResult.isAllowed) {
console.log('payment failed limits');
this.errorStore.addError('Limit Exceeded', state.limitsResult);
this.errorStore.displayErrors();
}
if (state.limitsResult.isAllowed && state.limitsResult.requiresMfa && !this.app.hasPassedMfa) {
console.log('limits requires mfa');
this.router.navigate(['/authenticate-method']);
return false;
}
const message = state.limitsResult.isAllowed ? 'passed limits guard' : 'failed limits guard';
console.log(message);
return state.limitsResult.isAllowed;
})
);
}
}