blob: 9ebe89e53b917b594f6183ffb66b63788ce974a6 [file] [log] [blame]
Matteo Scandolo43ffb672016-12-02 14:49:58 -08001/**
2 * Created by teone on 12/5/16.
3 */
4import {Directive, OnDestroy} from '@angular/core';
5import {AuthService} from '../services/rest/auth.service';
6import {Router} from '@angular/router';
7
8@Directive({
9 selector: '[xos-protected]',
10 providers: [AuthService]
11})
12export class ProtectedDirective implements OnDestroy {
13 private sub:any = null;
14
15 constructor(private authService:AuthService, private router:Router) {
16 console.log('protected directive');
17 if (!authService.isAuthenticated()) {
18 console.log('redirect');
19 this.router.navigate(['/login']);
20 }
21
22 // this.sub = this.authService.subscribe((val) => {
23 // if (!val.authenticated) {
24 // this.router.navigate(['LoggedoutPage']); // tells them they've been logged out (somehow)
25 // }
26 // });
27 }
28
29 ngOnDestroy() {
30 // if (this.sub != null) {
31 // this.sub.unsubscribe();
32 // }
33 }
34}