Skip to content

Commit

Permalink
Handle logout flow appropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
newmanw committed Sep 10, 2024
1 parent 10fdb8c commit fbc1928
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
6 changes: 5 additions & 1 deletion web-app/src/app/navigation/navigation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -22,6 +23,7 @@ export class NavigationComponent implements OnInit, OnDestroy {
feedChangedUsers = {}

constructor(
private router: Router,
private mapService: MapService,
private userService: UserService,
private eventService: EventService,
Expand Down Expand Up @@ -69,7 +71,9 @@ export class NavigationComponent implements OnInit, OnDestroy {
}

onLogout() {
this.userService.logout()
this.userService.logout().subscribe(() => {
this.router.navigate(['landing']);
})
}

onFilterChanged(filter) {
Expand Down
16 changes: 7 additions & 9 deletions web-app/src/app/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,7 +14,6 @@ export class UserService {
amAdmin: boolean

constructor(
private router: Router,
private httpClient: HttpClient,
private localStorageService: LocalStorageService
) { }
Expand Down Expand Up @@ -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<HttpEvent<any>> {
Expand Down

0 comments on commit fbc1928

Please sign in to comment.