Config and login
Change-Id: I81ffb9b8097620cb7870beaf1b1b315945eebec0
diff --git a/src/app/directives/protected.directive.ts b/src/app/directives/protected.directive.ts
new file mode 100644
index 0000000..9ebe89e
--- /dev/null
+++ b/src/app/directives/protected.directive.ts
@@ -0,0 +1,34 @@
+/**
+ * Created by teone on 12/5/16.
+ */
+import {Directive, OnDestroy} from '@angular/core';
+import {AuthService} from '../services/rest/auth.service';
+import {Router} from '@angular/router';
+
+@Directive({
+ selector: '[xos-protected]',
+ providers: [AuthService]
+})
+export class ProtectedDirective implements OnDestroy {
+ private sub:any = null;
+
+ constructor(private authService:AuthService, private router:Router) {
+ console.log('protected directive');
+ if (!authService.isAuthenticated()) {
+ console.log('redirect');
+ this.router.navigate(['/login']);
+ }
+
+ // this.sub = this.authService.subscribe((val) => {
+ // if (!val.authenticated) {
+ // this.router.navigate(['LoggedoutPage']); // tells them they've been logged out (somehow)
+ // }
+ // });
+ }
+
+ ngOnDestroy() {
+ // if (this.sub != null) {
+ // this.sub.unsubscribe();
+ // }
+ }
+}