1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-09 00:11:30 +01:00

handle registerRoute

This commit is contained in:
rr-bw 2024-08-30 15:40:23 -07:00
parent 9b28a0e01e
commit 2a58a69b08
No known key found for this signature in database
GPG Key ID: 3FA13C3ADEE51D5D
2 changed files with 37 additions and 2 deletions

View File

@ -48,7 +48,22 @@
<hr />
<!-- TODO-rr-bw: More here -->
<p class="tw-m-0 tw-text-sm">
{{ "newAroundHere" | i18n }}
<!-- Two notes:
(1) We check the value and validity of email so we don't send an invalid email to autofill
on load of register for both enter and mouse based navigation
(2) We use mousedown to trigger navigation so that the onBlur form validation does not fire
and move the create account link down the page on click which causes the user to miss actually
clicking on the link. Mousedown fires before onBlur.
-->
<a
[routerLink]="registerRoute$ | async"
[queryParams]="emailFormControl.valid ? { email: emailFormControl.value } : {}"
(mousedown)="goToRegister()"
>{{ "createAccount" | i18n }}</a
>
</p>
</ng-container>
<!-----------------------------------

View File

@ -5,7 +5,7 @@ import { ActivatedRoute, Router, RouterModule } from "@angular/router";
import { first, firstValueFrom, Subject, take, takeUntil } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { LoginEmailServiceAbstraction } from "@bitwarden/auth/common";
import { LoginEmailServiceAbstraction, RegisterRouteService } from "@bitwarden/auth/common";
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
@ -42,6 +42,7 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
private destroy$ = new Subject<void>();
clientType: ClientType;
registerRoute$ = this.registerRouteService.registerRoute$(); // TODO: remove when email verification flag is removed
showLoginWithDevice = false;
validatedEmail = false;
@ -54,6 +55,10 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
rememberEmail: [false],
});
get emailFormControl() {
return this.formGroup.controls.email;
}
get loggedEmail() {
return this.formGroup.value.email;
}
@ -72,6 +77,7 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
private loginService: LoginService,
private ngZone: NgZone,
private platformUtilsService: PlatformUtilsService,
private registerRouteService: RegisterRouteService,
private router: Router,
) {
this.clientType = this.platformUtilsService.getClientType();
@ -152,6 +158,20 @@ export class LoginComponentV2 implements OnInit, OnDestroy {
}
}
protected async goToRegister() {
// TODO: remove when email verification flag is removed
const registerRoute = await firstValueFrom(this.registerRoute$);
if (this.emailFormControl.valid) {
await this.router.navigate([registerRoute], {
queryParams: { email: this.emailFormControl.value },
});
return;
}
await this.router.navigate([registerRoute]);
}
private async getLoginWithDevice(email: string): Promise<void> {
try {
const deviceIdentifier = await this.appIdService.getAppId();