This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new f07dd033b1 TPv2 fix login redirect (#7335)
f07dd033b1 is described below

commit f07dd033b1701b2d969feaa1d3f45c094d38ce49
Author: ocket8888 <[email protected]>
AuthorDate: Tue Feb 7 14:23:28 2023 -0700

    TPv2 fix login redirect (#7335)
    
    * Fix returnUrl on login not working in TPv2
    
    * Fix login error not being caught
    
    That's a problem because it crashes the component, but what it should do
    when given a bad token is just drop you to login.
---
 .../src/app/login/login.component.spec.ts          |  2 +-
 .../src/app/login/login.component.ts               | 27 +++++++++++-----------
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/experimental/traffic-portal/src/app/login/login.component.spec.ts 
b/experimental/traffic-portal/src/app/login/login.component.spec.ts
index e54924d896..2cbe8f2941 100644
--- a/experimental/traffic-portal/src/app/login/login.component.spec.ts
+++ b/experimental/traffic-portal/src/app/login/login.component.spec.ts
@@ -18,7 +18,7 @@ import { FormsModule, ReactiveFormsModule } from 
"@angular/forms";
 import { MatDialog, MatDialogModule } from "@angular/material/dialog";
 import { Router } from "@angular/router";
 import { RouterTestingModule } from "@angular/router/testing";
-import {ReplaySubject} from "rxjs";
+import { ReplaySubject } from "rxjs";
 
 import { CurrentUserService } from 
"src/app/shared/currentUser/current-user.service";
 import { NavigationService } from 
"src/app/shared/navigation/navigation.service";
diff --git a/experimental/traffic-portal/src/app/login/login.component.ts 
b/experimental/traffic-portal/src/app/login/login.component.ts
index e589fa54d1..10a037972c 100644
--- a/experimental/traffic-portal/src/app/login/login.component.ts
+++ b/experimental/traffic-portal/src/app/login/login.component.ts
@@ -13,7 +13,7 @@
 */
 import { Component, OnInit } from "@angular/core";
 import { MatDialog } from "@angular/material/dialog";
-import { Router, ActivatedRoute } from "@angular/router";
+import { Router, ActivatedRoute, DefaultUrlSerializer } from "@angular/router";
 
 import { CurrentUserService } from 
"src/app/shared/currentUser/current-user.service";
 import { NavigationService } from 
"src/app/shared/navigation/navigation.service";
@@ -61,23 +61,21 @@ export class LoginComponent implements OnInit {
         * Runs initialization, setting up the post-login redirection from the 
query
         * string parameters.
         */
-       public ngOnInit(): void {
+       public async ngOnInit(): Promise<void> {
                const params = this.route.snapshot.queryParamMap;
                this.returnURL = params.get("returnUrl") ?? "core";
                const token = params.get("token");
                if (token) {
-                       this.auth.login(token).then(
-                               response => {
-                                       if (response) {
-                                               
this.navSvc.headerHidden.next(false);
-                                               
this.navSvc.sidebarHidden.next(false);
-                                               
this.router.navigate(["/core/me"], {queryParams: {edit: true, updatePassword: 
true}});
-                                       }
-                               },
-                               err => {
-                                       console.error("login with token 
failed:", err);
+                       try {
+                               const response = await this.auth.login(token);
+                               if (response) {
+                                       this.navSvc.headerHidden.next(false);
+                                       this.navSvc.sidebarHidden.next(false);
+                                       this.router.navigate(["/core/me"], 
{queryParams: {edit: true, updatePassword: true}});
                                }
-                       );
+                       } catch (e) {
+                               console.error("token login failed:", e);
+                       }
                }
        }
 
@@ -97,7 +95,8 @@ export class LoginComponent implements OnInit {
                        if (response) {
                                this.navSvc.headerHidden.next(false);
                                this.navSvc.sidebarHidden.next(false);
-                               this.router.navigate([this.returnURL]);
+                               const tree = new 
DefaultUrlSerializer().parse(this.returnURL);
+                               
this.router.navigate(tree.root.children.primary.segments.map(s=>s.path), 
{queryParams: tree.queryParams});
                        }
                } catch (err) {
                        console.error("login failed:", err);

Reply via email to