ministry.auth.guard.ts 656 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { MINISTRY_ROLE } from '../constants';
import { Router } from '@angular/router';

@Injectable()
export default class MinistryAuthGuard implements CanActivate {

  constructor(private authService: AuthService, private router: Router) {}

  canActivate() {
    return this.authService.isLoggedIn(MINISTRY_ROLE).then(loggedIn => {
        if (!loggedIn) {
            this.router.navigate(['/ministry/logout']);
        }
        return loggedIn;
    }).catch(err => {
        return false;
    });
  }
}