Ajout un "logout"

This commit is contained in:
Sébastien André
2020-03-13 16:30:41 +01:00
parent e7e7f3f62b
commit 11d4127c20
2 changed files with 18 additions and 1 deletions

View File

@@ -1,5 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { ServiceComm } from '../services/service-comm.service';
import { Router } from '@angular/router';
import { AuthenticationService } from '../services/authentication.service';
import { User } from '../models/user';
@Component({
selector: 'app-root',
@@ -9,8 +12,15 @@ import { ServiceComm } from '../services/service-comm.service';
export class AppComponent implements OnInit {
title = 'app';
showMenu = false;
currentUser: User;
constructor(private serviceComm: ServiceComm) { }
constructor(
private router: Router,
private authenticationService: AuthenticationService,
private serviceComm: ServiceComm
) {
this.authenticationService.currentUser.subscribe(x => this.currentUser = x);
}
ngOnInit() {
this.serviceComm.componentTitle.subscribe(title => (this.title = title));
@@ -19,4 +29,10 @@ export class AppComponent implements OnInit {
toggleMenu() {
this.showMenu = !this.showMenu;
}
logout() {
this.authenticationService.logout();
this.showMenu = !this.showMenu;
this.router.navigate(['/login']);
}
}