src/app/providers/guards/plaid.guard.ts
Methods |
constructor(sessionStore: SessionStore, router: Router)
|
|||||||||
Defined in src/app/providers/guards/plaid.guard.ts:14
|
|||||||||
Parameters :
|
canActivate | |||||||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
|
|||||||||
Defined in src/app/providers/guards/plaid.guard.ts:17
|
|||||||||
Parameters :
Returns :
any
|
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot
} from '@angular/router';
import { filter, map } from 'rxjs/operators';
import { SessionStore } from '../stores';
const PLAID = 'PLAID';
@Injectable()
export class PlaidGuard implements CanActivate {
constructor(private sessionStore: SessionStore, private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.sessionStore.session$.pipe(
filter(
session =>
session !== null &&
session !== undefined &&
session.accountVerificationTypes !== null &&
session.accountVerificationTypes !== undefined &&
session.accountVerificationTypes.length !== null &&
session.accountVerificationTypes.length !== undefined
),
map(session => {
console.log(session.accountVerificationTypes);
const allowed = session.accountVerificationTypes.includes(PLAID);
if (!allowed) {
console.log('plaid not allowed redirecting to microdeposit');
// go to microdeposit
this.router.navigate(['template/create']);
return false;
}
console.log('plaid allowed');
return true; // go to plaid
})
);
}
}