regionedu.auth.guard.ts 645 Bytes
Newer Older
Open Source Developer's avatar
trans    
Open Source Developer committed
1
2
3
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from '../services/auth.service';
Open Source Developer's avatar
Open Source Developer committed
4
import { PDE_ROLE } from '../constants';
5
import { Router } from '@angular/router';
Open Source Developer's avatar
trans    
Open Source Developer committed
6
7
8
9

@Injectable()
export default class RegionEduAuthGuard implements CanActivate {

10
  constructor(private authService: AuthService, private router: Router) {}
Open Source Developer's avatar
trans    
Open Source Developer committed
11
12

  canActivate() {
13
14
15
16
17
18
19
20
    return this.authService.isLoggedIn(PDE_ROLE).then(loggedIn => {
        if (!loggedIn) {
            this.router.navigate(['/school/logout']);
        }
        return loggedIn;
    }).catch(err => {
        return false;
    });
Open Source Developer's avatar
trans    
Open Source Developer committed
21
22
  }
}