Skip to content

Commit bd9a243

Browse files
committed
Refactor SSO mode detection
1 parent 617fa95 commit bd9a243

File tree

2 files changed

+26
-33
lines changed

2 files changed

+26
-33
lines changed

client/src/app/app.component.ts

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import { catchError } from 'rxjs/operators';
66
import { EMPTY } from 'rxjs';
77
import { EditModeFlag } from './modules/edit-mode/domain/edit-mode';
88
import { StorageService } from './modules/storage/services/storage.service';
9-
import { ActivatedRoute, NavigationStart, Router } from '@angular/router';
9+
import { NavigationStart, Router } from '@angular/router';
1010
import { ProjectService } from './modules/project/services/project.service';
1111
import { ProjectData, ProjectStorage } from './domain/project';
1212
import { AuthenticationService } from './modules/authentication/services/authentication.service';
13-
import { HttpErrorResponse } from '@angular/common/http';
1413

1514
@Component({
1615
selector: 'app-root',
@@ -29,7 +28,6 @@ export class AppComponent implements OnInit {
2928
constructor(
3029
public editMode: EditModeService,
3130
public router: Router,
32-
private activatedRoute: ActivatedRoute,
3331
private matIconRegistry: MatIconRegistry,
3432
private domSanitizer: DomSanitizer,
3533
private renderer: Renderer2,
@@ -42,22 +40,18 @@ export class AppComponent implements OnInit {
4240
}
4341

4442
ngOnInit() {
45-
this.activatedRoute.queryParams.subscribe(params => {
46-
if (params['sso']) {
47-
this.setSsoMode();
48-
}
49-
});
43+
this.authenticationService.checkAndSetSsoMode();
5044

5145
this.router.events.subscribe(event => {
5246
if (event instanceof NavigationStart) {
5347
if (event.url === '/') {
5448
this.loadAllProjects();
49+
} else if (event.url === '/login' || event.url === '/logout') {
50+
this.showLogoutButton = false;
51+
this.isLoading = false;
5552
}
56-
this.isLoading = false;
5753
}
5854
});
59-
60-
this.checkShowLogoutButton();
6155
}
6256

6357
getEditModeStatus() {
@@ -74,23 +68,6 @@ export class AppComponent implements OnInit {
7468
});
7569
}
7670

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-
9471
private checkRedirectToProjectDetail() {
9572
const projectKey = this.getProjectKeyFormStorage();
9673
if (projectKey) {
@@ -109,7 +86,7 @@ export class AppComponent implements OnInit {
10986
this.projectService
11087
.getAllProjects()
11188
.pipe(
112-
catchError((response: HttpErrorResponse) => {
89+
catchError(() => {
11390
// show generic error page
11491
this.isLoading = false;
11592
this.isError = true;

client/src/app/modules/authentication/services/authentication.service.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Inject, Injectable } from '@angular/core';
22
import { HttpClient, HttpHeaders } from '@angular/common/http';
33
import { API_AUTH_URL, API_LOGOUT_URL } from '../../../tokens';
4+
import { ActivatedRoute, Router } from '@angular/router';
45

56
@Injectable({
67
providedIn: 'root'
@@ -10,18 +11,25 @@ export class AuthenticationService {
1011

1112
constructor(
1213
private httpClient: HttpClient,
14+
private activatedRoute: ActivatedRoute,
15+
private router: Router,
1316
@Inject(API_AUTH_URL) private apiAuthUrl: string,
1417
@Inject(API_LOGOUT_URL) private apiLogoutUrl: string
1518
) {}
1619

17-
set sso(enabled: boolean) {
18-
this._sso = enabled;
19-
}
20-
2120
get sso(): boolean {
2221
return this._sso;
2322
}
2423

24+
checkAndSetSsoMode() {
25+
this.activatedRoute.queryParams.subscribe(params => {
26+
if (params['sso']) {
27+
this._sso = true;
28+
this.removeSsoUrlParam();
29+
}
30+
});
31+
}
32+
2533
login(username: string, password: string): any {
2634
const formData: FormData = new FormData();
2735
formData.append('username', username);
@@ -36,4 +44,12 @@ export class AuthenticationService {
3644
logout(): any {
3745
return this.httpClient.get<any>(this.apiLogoutUrl);
3846
}
47+
48+
private removeSsoUrlParam() {
49+
this.router.navigate([], {
50+
queryParams: {
51+
sso: null
52+
}
53+
});
54+
}
3955
}

0 commit comments

Comments
 (0)