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 { ColorThemeService } from './services/colorTheme.service';
import { AuthService } from './services/auth.service'; import { AuthService } from './services/auth.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ViewChild } from '@angular/core';
import { MatSidenav } from '@angular/material/sidenav';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
@ -13,6 +15,8 @@ export class AppComponent {
darkThemeIsActive: boolean = false; darkThemeIsActive: boolean = false;
loggedIn = false; loggedIn = false;
@ViewChild('sidenav') public sideNav:MatSidenav;
constructor( constructor(
private renderer: Renderer2, private renderer: Renderer2,
private themeService: ColorThemeService, private themeService: ColorThemeService,
@ -31,5 +35,6 @@ export class AppComponent {
logout() { logout() {
this.authService.logout().subscribe().add(() => this.router.navigate(['login'])); this.authService.logout().subscribe().add(() => this.router.navigate(['login']));
this.sideNav.close();
} }
} }

@ -29,7 +29,7 @@ export class LoginComponent implements OnInit {
this.authService this.authService
.login(this.email.value, this.password.value) .login(this.email.value, this.password.value)
.subscribe( .subscribe(
() => this.router.navigate(['bikes']), () => this.router.navigate(['tableOverview']),
(error) => { (error) => {
this.errorOccurred = true; this.errorOccurred = true;
this.errorMessage = this.errorMessage =

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; 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 { environment } from '../../environments/environment';
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
@ -43,7 +43,7 @@ export class AuthService {
logout() { logout() {
// remove token from local storage to log user out // remove token from local storage to log user out
return this.http 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('requestToken');
localStorage.removeItem('refreshToken'); localStorage.removeItem('refreshToken');
this.checkIfUserIsLoggedIn(); this.checkIfUserIsLoggedIn();

Loading…
Cancel
Save