Fix logout bug

pull/1/head
Max Ehrlicher-Schmidt 4 years ago
parent f363afdb55
commit 5b5baa6f88

@ -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();
}
}

@ -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 =

@ -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<any>(`${environment.authUrl}/logout`, { request_token: this.requestToken }).pipe(tap(() => {
.post<any>(`${environment.authUrl}/logout`, { request_token: this.requestToken }).pipe(finalize(() => {
localStorage.removeItem('requestToken');
localStorage.removeItem('refreshToken');
this.checkIfUserIsLoggedIn();

Loading…
Cancel
Save