Skip to content

Commit 617fa95

Browse files
committed
Refactor logout button display & handling of 401 responses
1 parent b2c2693 commit 617fa95

File tree

4 files changed

+33
-29
lines changed

4 files changed

+33
-29
lines changed

client/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="logo">
55
<h1>ODS Provisioning</h1>
66
</div>
7-
<div class="user-area" *ngIf="showLogoutButton()">
7+
<div class="user-area" *ngIf="showLogoutButton">
88
<div class="user-area__logout">
99
<a
1010
mat-mini-fab

client/src/app/app.component.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class AppComponent implements OnInit {
2222
isError: boolean;
2323
isNewProjectFormActive = false;
2424
hideSidebar = false;
25+
showLogoutButton = true;
2526

2627
projects: ProjectData[] = [];
2728

@@ -55,24 +56,8 @@ export class AppComponent implements OnInit {
5556
this.isLoading = false;
5657
}
5758
});
58-
}
5959

60-
private setSsoMode() {
61-
this.authenticationService.sso = true;
62-
this.router.navigate([], {
63-
queryParams: {
64-
sso: null
65-
}
66-
});
67-
}
68-
69-
showLogoutButton() {
70-
this.router.events.subscribe(event => {
71-
if (event instanceof NavigationStart && (event.url === 'login' || event.url === 'logout')) {
72-
return false;
73-
}
74-
return true;
75-
});
60+
this.checkShowLogoutButton();
7661
}
7762

7863
getEditModeStatus() {
@@ -89,10 +74,29 @@ export class AppComponent implements OnInit {
8974
});
9075
}
9176

77+
private checkShowLogoutButton() {
78+
return this.router.events.subscribe(event => {
79+
if (event instanceof NavigationStart && (event.url === '/login' || event.url === '/logout')) {
80+
this.showLogoutButton = false;
81+
}
82+
});
83+
}
84+
85+
private setSsoMode() {
86+
this.authenticationService.sso = true;
87+
this.router.navigate([], {
88+
queryParams: {
89+
sso: null
90+
}
91+
});
92+
}
93+
9294
private checkRedirectToProjectDetail() {
9395
const projectKey = this.getProjectKeyFormStorage();
9496
if (projectKey) {
9597
this.router.navigateByUrl(`/project/${projectKey}`);
98+
} else {
99+
this.router.navigateByUrl('/project');
96100
}
97101
}
98102

@@ -106,13 +110,10 @@ export class AppComponent implements OnInit {
106110
.getAllProjects()
107111
.pipe(
108112
catchError((response: HttpErrorResponse) => {
109-
if (response.error.status === 401) {
110-
// interceptor takes control and redirects to login
111-
return EMPTY;
112-
}
113113
// show generic error page
114114
this.isLoading = false;
115115
this.isError = true;
116+
return EMPTY;
116117
})
117118
)
118119
.subscribe((response: ProjectData[]) => {

client/src/app/modules/error-handler/http-request-interceptor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable } from '@angular/core';
22
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest } from '@angular/common/http';
3-
import { Observable, throwError } from 'rxjs';
3+
import { EMPTY, Observable, throwError } from 'rxjs';
44
import { catchError } from 'rxjs/operators';
55
import { Router } from '@angular/router';
66
import { AuthenticationService } from '../authentication/services/authentication.service';
@@ -42,6 +42,7 @@ export class HttpRequestInterceptor implements HttpInterceptor {
4242
catchError((error: HttpErrorResponse) => {
4343
if (error.status === 401) {
4444
this.router.navigateByUrl(this.authenticationService.sso ? '/' : '/login');
45+
return EMPTY;
4546
}
4647

4748
// TODO Improvement idea:

client/src/assets/icons/error.svg

Lines changed: 8 additions & 6 deletions
Loading

0 commit comments

Comments
 (0)