1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +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

@@ -39,8 +39,7 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
formPromise: Promise<any>;
emailPromise: Promise<any>;
identifier: string = null;
redirectPath: string;
sessionId: string;
redirectUrl: string;
onSuccessfulLogin: () => Promise<any>;
onSuccessfulLoginNavigate: () => Promise<any>;
@@ -76,15 +75,6 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
if (qParams.identifier != null) {
this.identifier = qParams.identifier;
}
if (qParams.redirectPath != null) {
this.redirectPath = qParams.redirectPath;
this.successRoute = this.redirectPath;
}
if (qParams.sessionId != null) {
this.sessionId = qParams.sessionId;
}
});
if (this.needsLock) {
@@ -203,6 +193,13 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
}
async doSubmit() {
// 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);
}
this.formPromise = this.authService.logInTwoFactor(
new TokenTwoFactorRequest(this.selectedProviderType, this.token, this.remember),
this.captchaToken
@@ -228,12 +225,7 @@ export class TwoFactorComponent extends CaptchaProtectedComponent implements OnI
await this.onSuccessfulLoginNavigate();
} else {
this.loginService.clearValues();
this.router.navigate([this.successRoute], {
queryParams: {
identifier: this.identifier,
sessionId: this.sessionId,
},
});
this.router.navigateByUrl(this.successRoute);
}
}