Skip to content

Commit 5128364

Browse files
authored
fix(ui): redirect mfa on project pages (#6235)
1 parent a3c8ff0 commit 5128364

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

ui/src/app/service/authentication/error.interceptor.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
22
import { Injectable } from '@angular/core';
3-
import { NavigationError, Router } from '@angular/router';
3+
import { NavigationStart, Router } from '@angular/router';
44
import { TranslateService } from '@ngx-translate/core';
55
import { Store } from '@ngxs/store';
66
import { ToastService } from 'app/shared/toast/ToastService';
@@ -10,13 +10,18 @@ import { catchError, filter, first } from 'rxjs/operators';
1010

1111
@Injectable()
1212
export class ErrorInterceptor implements HttpInterceptor {
13+
lastNavigatedURL: string = '';
1314

1415
constructor(
1516
private _toast: ToastService,
1617
private _translate: TranslateService,
1718
private _store: Store,
1819
private _router: Router
19-
) { }
20+
) {
21+
this._router.events
22+
.pipe(filter((e): e is NavigationStart => e instanceof NavigationStart))
23+
.subscribe(e => this.lastNavigatedURL = e.url);
24+
}
2025

2126
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
2227
return next.handle(req).pipe(
@@ -40,25 +45,18 @@ export class ErrorInterceptor implements HttpInterceptor {
4045
if (e.error.message) {
4146
// 194 is the error for "MFA required. See https://github.com/ovh/cds/blob/master/sdk/error.go#L205"
4247
if (e.error.id === 194 && confirm(`${e.error.message}.\nDo you want to login using MFA ?`)) {
43-
this._router.events
44-
.pipe(
45-
filter((e): e is NavigationError => e instanceof NavigationError),
46-
first()
47-
)
48-
.subscribe(e => {
49-
this._store.dispatch(new SignoutCurrentUser()).subscribe(() => {
50-
this._router.navigate(['/auth/ask-signin/corporate-sso'], {
51-
queryParams: {
52-
redirect_uri: e.url,
53-
require_mfa: true
54-
}
55-
});
56-
});
48+
this._store.dispatch(new SignoutCurrentUser()).subscribe(() => {
49+
this._router.navigate(['/auth/ask-signin/corporate-sso'], {
50+
queryParams: {
51+
redirect_uri: this.lastNavigatedURL,
52+
require_mfa: true
53+
}
5754
});
58-
55+
});
5956
return observableThrowError(e);
6057
}
6158
this._toast.errorHTTP(e.status, e.error.message, e.error.from, e.error.request_id);
59+
this._router.navigate(['/home']);
6260
return observableThrowError(e);
6361
}
6462

ui/src/app/views/project/show/project.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ export class ProjectShowComponent implements OnInit, OnDestroy, AfterViewInit {
197197

198198
refreshDatas(key: string): void {
199199
let opts = [new LoadOpts('withLabels', 'labels')];
200-
this._store.dispatch(new FetchProject({ projectKey: key, opts }))
201-
.subscribe(null, () => this._router.navigate(['/home']));
200+
this._store.dispatch(new FetchProject({ projectKey: key, opts }));
202201
}
203202

204203
updateFav() {

0 commit comments

Comments
 (0)