1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

Refactored components to make the redirectUrl more generic, fixed code review comments

This commit is contained in:
gbubemismith
2023-08-23 01:36:23 -04:00
parent ef4a1d9b7b
commit 6a05ba3ad0
6 changed files with 66 additions and 74 deletions

View File

@@ -41,8 +41,7 @@ export class LockComponent implements OnInit, OnDestroy {
biometricLock: boolean;
biometricText: string;
hideInput: boolean;
redirectPath: string;
sessionId: string;
redirectUrl: string;
protected successRoute = "vault";
protected forcePasswordResetRoute = "update-temp-password";
@@ -72,21 +71,11 @@ export class LockComponent implements OnInit, OnDestroy {
protected policyApiService: PolicyApiServiceAbstraction,
protected policyService: InternalPolicyService,
protected passwordStrengthService: PasswordStrengthServiceAbstraction,
protected dialogService: DialogServiceAbstraction,
protected route: ActivatedRoute
protected route: ActivatedRoute,
protected dialogService: DialogServiceAbstraction
) {}
async ngOnInit() {
this.route?.queryParams.subscribe((params) => {
this.redirectPath = params?.redirectPath;
this.sessionId = params?.sessionId;
});
//use redirectPath to redirect to a specific page after successful login
if (this.redirectPath) {
this.successRoute = this.redirectPath;
}
this.stateService.activeAccount$
.pipe(
concatMap(async () => {
@@ -279,6 +268,13 @@ export class LockComponent implements OnInit, OnDestroy {
await this.stateService.setEverBeenUnlocked(true);
this.messagingService.send("unlocked");
// The `redirectUrl` parameter determines the target route after a successful login.
// If provided in the URL's query parameters, the user will be redirected
// to the specified path once they are authenticated.
if (this.route.snapshot.queryParams.redirectUrl) {
this.successRoute = decodeURIComponent(this.route.snapshot.queryParams.redirectUrl);
}
if (evaluatePasswordAfterUnlock) {
try {
// If we do not have any saved policies, attempt to load them from the service
@@ -304,11 +300,7 @@ export class LockComponent implements OnInit, OnDestroy {
if (this.onSuccessfulSubmit != null) {
await this.onSuccessfulSubmit();
} else if (this.router != null) {
this.router.navigate([this.successRoute], {
queryParams: {
sessionId: this.sessionId,
},
});
this.router.navigateByUrl(this.successRoute);
}
}