From 5b5baa6f88ac1ae7e7f411ff8018a006f03d49a4 Mon Sep 17 00:00:00 2001 From: Max Ehrlicher-Schmidt Date: Tue, 22 Sep 2020 17:35:04 +0200 Subject: [PATCH] Fix logout bug --- src/app/app.component.ts | 5 +++++ src/app/pages/login/login.component.ts | 2 +- src/app/services/auth.service.ts | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1f6af50..e568f0e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -2,6 +2,8 @@ import { Component, Renderer2 } from '@angular/core'; import { ColorThemeService } from './services/colorTheme.service'; import { AuthService } from './services/auth.service'; import { Router } from '@angular/router'; +import { ViewChild } from '@angular/core'; +import { MatSidenav } from '@angular/material/sidenav'; @Component({ selector: 'app-root', @@ -13,6 +15,8 @@ export class AppComponent { darkThemeIsActive: boolean = false; loggedIn = false; + @ViewChild('sidenav') public sideNav:MatSidenav; + constructor( private renderer: Renderer2, private themeService: ColorThemeService, @@ -31,5 +35,6 @@ export class AppComponent { logout() { this.authService.logout().subscribe().add(() => this.router.navigate(['login'])); + this.sideNav.close(); } } diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index 68903e2..3835504 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -29,7 +29,7 @@ export class LoginComponent implements OnInit { this.authService .login(this.email.value, this.password.value) .subscribe( - () => this.router.navigate(['bikes']), + () => this.router.navigate(['tableOverview']), (error) => { this.errorOccurred = true; this.errorMessage = diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index d0c029f..c20e10e 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { map, tap } from 'rxjs/operators'; +import { finalize, map, tap } from 'rxjs/operators'; import { environment } from '../../environments/environment'; import { BehaviorSubject } from 'rxjs'; @@ -43,7 +43,7 @@ export class AuthService { logout() { // remove token from local storage to log user out return this.http - .post(`${environment.authUrl}/logout`, { request_token: this.requestToken }).pipe(tap(() => { + .post(`${environment.authUrl}/logout`, { request_token: this.requestToken }).pipe(finalize(() => { localStorage.removeItem('requestToken'); localStorage.removeItem('refreshToken'); this.checkIfUserIsLoggedIn();