student.auth.guard.ts 678 Bytes
Newer Older
1
2
3
4
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from '../services/auth.service';
import { STUDENT_ROLE } from '../constants';
5
import { Router } from '@angular/router';
6
7
8
9

@Injectable()
export default class StudentAuthGuard implements CanActivate {

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

  canActivate() {
13
14
15
16
17
18
19
20
21
    return this.authService.isLoggedIn(STUDENT_ROLE).then(loggedIn => {
        if (!loggedIn) {
            this.router.navigate(['/logout']);
        }
        return loggedIn;
    }).catch(err => {
        console.log("exception");
        return false;
    });
22
23
  }
}