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

riemer pushed a commit to branch SP-1140
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit d91c98f80fbe503b3d0d3cb60d97c385e0058c37
Author: Dominik Riemer <[email protected]>
AuthorDate: Fri Jan 20 22:40:37 2023 +0100

    Redirect to previous view after successful login (#1140)
---
 ui/src/app/_guards/auth.can-activate-children.guard.ts | 4 +++-
 ui/src/app/login/components/login/login.component.ts   | 8 ++++++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ui/src/app/_guards/auth.can-activate-children.guard.ts 
b/ui/src/app/_guards/auth.can-activate-children.guard.ts
index cad3cf7ac..698b27d4b 100644
--- a/ui/src/app/_guards/auth.can-activate-children.guard.ts
+++ b/ui/src/app/_guards/auth.can-activate-children.guard.ts
@@ -37,7 +37,9 @@ export class AuthCanActivateChildrenGuard implements 
CanActivateChild {
             return true;
         }
         this.authService.logout();
-        this.router.navigate(['/login']);
+        this.router.navigate(['/login'], {
+            queryParams: { returnUrl: state.url },
+        });
 
         return false;
     }
diff --git a/ui/src/app/login/components/login/login.component.ts 
b/ui/src/app/login/components/login/login.component.ts
index 8ad2670a8..783999eed 100644
--- a/ui/src/app/login/components/login/login.component.ts
+++ b/ui/src/app/login/components/login/login.component.ts
@@ -19,7 +19,7 @@
 import { ShepherdService } from '../../../services/tour/shepherd.service';
 import { Component, OnInit } from '@angular/core';
 import { LoginService } from '../../services/login.service';
-import { Router } from '@angular/router';
+import { ActivatedRoute, Router } from '@angular/router';
 import { AuthService } from '../../../services/auth.service';
 import { LoginModel } from './login.model';
 import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators 
} from '@angular/forms';
@@ -39,8 +39,11 @@ export class LoginComponent implements OnInit {
 
     loginSettings: LoginModel;
 
+    returnUrl: string;
+
     constructor(private loginService: LoginService,
                 private router: Router,
+                private route: ActivatedRoute,
                 private shepherdService: ShepherdService,
                 private authService: AuthService,
                 private fb: UntypedFormBuilder) {
@@ -62,6 +65,7 @@ export class LoginComponent implements OnInit {
           this.credentials.password = v.password;
         });
       });
+      this.returnUrl = this.route.snapshot.queryParams.returnUrl || '';
     }
 
 
@@ -73,7 +77,7 @@ export class LoginComponent implements OnInit {
             .subscribe(response => { // success
                     this.authService.login(response);
                     this.loading = false;
-                    this.router.navigate(['']);
+                    this.router.navigateByUrl(this.returnUrl);
                 }, response => { // error
                     this.loading = false;
                     this.authenticationFailed = true;

Reply via email to