blob: 199cc101ff9deff22cea8047c6862de70b0a4a13 [file] [log] [blame]
Matteo Scandolo8b9f1642016-12-05 17:08:26 -08001/// <reference path="../../../../typings/index.d.ts"/>
2import {Component, OnInit} from '@angular/core';
3import {Router} from '@angular/router';
4import {AuthService} from '../../services/rest/auth.service';
5
6@Component({
7 selector: 'xos-logout',
8 template: `
9 <button *ngIf="show" (click)="logout()">Logout</button>
10 `,
11 providers: [AuthService],
12})
13export class LogoutComponent implements OnInit {
14 public show: boolean = false;
15 constructor(private AuthService: AuthService, private router: Router) {
16 }
17
18 ngOnInit() {
19 if (this.AuthService.isAuthenticated()) {
20 this.show = true;
21 }
22 }
23
24 logout() {
25 this.AuthService.logout()
26 .subscribe(
27 () => {
28 this.router.navigate(['/login']);
29 }
30 );
31 }
32}
33