Skip to content

Commit

Permalink
Merge pull request #1141 from apache/SP-1140
Browse files Browse the repository at this point in the history
Redirect to previous view after successful login (#1140)
  • Loading branch information
dominikriemer committed Jan 22, 2023
2 parents 4655a9a + f6406e0 commit aa2e1c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 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
11 changes: 5 additions & 6 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 {
Expand All @@ -42,10 +42,12 @@ export class LoginComponent implements OnInit {
credentials: any;

loginSettings: LoginModel;
returnUrl: string;

constructor(
private loginService: LoginService,
private router: Router,
private route: ActivatedRoute,
private shepherdService: ShepherdService,
private authService: AuthService,
private fb: UntypedFormBuilder,
Expand Down Expand Up @@ -73,6 +75,7 @@ export class LoginComponent implements OnInit {
this.credentials.username = v.username;
this.credentials.password = v.password;
});
this.returnUrl = this.route.snapshot.queryParams.returnUrl || '';
});
}

Expand All @@ -84,7 +87,7 @@ export class LoginComponent implements OnInit {
// success
this.authService.login(response);
this.loading = false;
this.router.navigate(['']);
this.router.navigateByUrl(this.returnUrl);
},
response => {
// error
Expand All @@ -93,8 +96,4 @@ export class LoginComponent implements OnInit {
},
);
}

setSheperdServiceDelay() {
// this.ShepherdService.setTimeWaitMillies(100);
}
}

0 comments on commit aa2e1c5

Please sign in to comment.