Skip to content

Commit

Permalink
Redirect to previous view after successful login (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikriemer committed Jan 20, 2023
1 parent db127e9 commit d91c98f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ui/src/app/_guards/auth.can-activate-children.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions ui/src/app/login/components/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand All @@ -62,6 +65,7 @@ export class LoginComponent implements OnInit {
this.credentials.password = v.password;
});
});
this.returnUrl = this.route.snapshot.queryParams.returnUrl || '';
}


Expand All @@ -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;
Expand Down

0 comments on commit d91c98f

Please sign in to comment.