File

src/app/providers/guards/plaid.guard.ts

Index

Methods

Constructor

constructor(sessionStore: SessionStore, router: Router)
Parameters :
Name Type Optional
sessionStore SessionStore No
router Router No

Methods

canActivate
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
Parameters :
Name Type Optional
route ActivatedRouteSnapshot No
state RouterStateSnapshot No
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
      })
    );
  }
}

results matching ""

    No results matching ""