From fbc1928aebec4cca018ced0618cfcfc0bc120107 Mon Sep 17 00:00:00 2001 From: William Newman <3382274+newmanw@users.noreply.github.com> Date: Tue, 10 Sep 2024 08:09:55 -0600 Subject: [PATCH] Handle logout flow appropriately --- .../src/app/navigation/navigation.component.ts | 6 +++++- web-app/src/app/user/user.service.ts | 16 +++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/web-app/src/app/navigation/navigation.component.ts b/web-app/src/app/navigation/navigation.component.ts index 99fe4868d..210f8dac4 100644 --- a/web-app/src/app/navigation/navigation.component.ts +++ b/web-app/src/app/navigation/navigation.component.ts @@ -5,6 +5,7 @@ import { UserService } from '../user/user.service'; import { EventService } from '../event/event.service'; import { PollingService } from '../event/polling.service'; import * as _ from 'underscore'; +import { Router } from '@angular/router'; @Component({ selector: 'navigation', @@ -22,6 +23,7 @@ export class NavigationComponent implements OnInit, OnDestroy { feedChangedUsers = {} constructor( + private router: Router, private mapService: MapService, private userService: UserService, private eventService: EventService, @@ -69,7 +71,9 @@ export class NavigationComponent implements OnInit, OnDestroy { } onLogout() { - this.userService.logout() + this.userService.logout().subscribe(() => { + this.router.navigate(['landing']); + }) } onFilterChanged(filter) { diff --git a/web-app/src/app/user/user.service.ts b/web-app/src/app/user/user.service.ts index c0ba60bf1..8bafcf0da 100644 --- a/web-app/src/app/user/user.service.ts +++ b/web-app/src/app/user/user.service.ts @@ -1,6 +1,5 @@ import { HttpClient, HttpContext, HttpEvent } from '@angular/common/http' import { Injectable } from '@angular/core' -import { Router } from '@angular/router' import { Observable, Subject, tap } from 'rxjs' import { LocalStorageService } from '../http/local-storage.service' import { BYPASS_TOKEN } from '../http/token.interceptor' @@ -15,7 +14,6 @@ export class UserService { amAdmin: boolean constructor( - private router: Router, private httpClient: HttpClient, private localStorageService: LocalStorageService ) { } @@ -133,13 +131,13 @@ export class UserService { } logout() { - const observable = this.httpClient.post('/api/logout', null, { responseType: 'text' }) - observable.subscribe(() => { - this.clearUser(); - this.router.navigate(['landing']); - }) - - return observable; + return this.httpClient + .post('/api/logout', { responseType: 'text' }) + .pipe( + tap(() => { + this.clearUser() + }) + ) } saveProfile(user: any): Observable> {