From 0a0cbde5b39d89975bb926763ba707ee764c9684 Mon Sep 17 00:00:00 2001 From: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com> Date: Thu, 29 Aug 2024 13:55:09 -0400 Subject: [PATCH] Auth/PM-11318 - Registration With Email Verification - Login After Registration (#10783) * PM-11318 - Registration Finish - Log user in after registration * PM-11318 - Adjust registration and login message to be one msg * PM-11318 - RegistrationFinish - Adjust messaging based on product feedback. * PM-11318 - RegistrationFinishComp - Tweak redirect and error logic. --- apps/browser/src/_locales/en/messages.json | 6 ++++ apps/desktop/src/locales/en/messages.json | 6 ++++ apps/web/src/locales/en/messages.json | 6 ++++ .../registration-finish.component.ts | 34 +++++++++++++++++-- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/apps/browser/src/_locales/en/messages.json b/apps/browser/src/_locales/en/messages.json index 29396a8bcf..6d67047bcb 100644 --- a/apps/browser/src/_locales/en/messages.json +++ b/apps/browser/src/_locales/en/messages.json @@ -683,6 +683,12 @@ "newAccountCreated": { "message": "Your new account has been created! You may now log in." }, + "newAccountCreated2": { + "message": "Your new account has been created!" + }, + "youHaveBeenLoggedIn": { + "message": "You have been logged in!" + }, "youSuccessfullyLoggedIn": { "message": "You successfully logged in" }, diff --git a/apps/desktop/src/locales/en/messages.json b/apps/desktop/src/locales/en/messages.json index 1bd3718550..5345c6e15a 100644 --- a/apps/desktop/src/locales/en/messages.json +++ b/apps/desktop/src/locales/en/messages.json @@ -603,6 +603,12 @@ "newAccountCreated": { "message": "Your new account has been created! You may now log in." }, + "newAccountCreated2": { + "message": "Your new account has been created!" + }, + "youHaveBeenLoggedIn": { + "message": "You have been logged in!" + }, "masterPassSent": { "message": "We've sent you an email with your master password hint." }, diff --git a/apps/web/src/locales/en/messages.json b/apps/web/src/locales/en/messages.json index 2583747b4f..6476b70fd0 100644 --- a/apps/web/src/locales/en/messages.json +++ b/apps/web/src/locales/en/messages.json @@ -964,6 +964,12 @@ "newAccountCreated": { "message": "Your new account has been created! You may now log in." }, + "newAccountCreated2": { + "message": "Your new account has been created!" + }, + "youHaveBeenLoggedIn": { + "message": "You have been logged in!" + }, "trialAccountCreated": { "message": "Account created successfully." }, diff --git a/libs/auth/src/angular/registration/registration-finish/registration-finish.component.ts b/libs/auth/src/angular/registration/registration-finish/registration-finish.component.ts index 03886fe88d..3c7e31b5de 100644 --- a/libs/auth/src/angular/registration/registration-finish/registration-finish.component.ts +++ b/libs/auth/src/angular/registration/registration-finish/registration-finish.component.ts @@ -10,9 +10,11 @@ import { RegisterVerificationEmailClickedRequest } from "@bitwarden/common/auth/ import { HttpStatusCode } from "@bitwarden/common/enums"; import { ErrorResponse } from "@bitwarden/common/models/response/error.response"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; +import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service"; import { ToastService } from "@bitwarden/components"; +import { LoginStrategyServiceAbstraction, PasswordLoginCredentials } from "../../../common"; import { InputPasswordComponent } from "../../input-password/input-password.component"; import { PasswordInputResult } from "../../input-password/password-input-result"; @@ -46,6 +48,8 @@ export class RegistrationFinishComponent implements OnInit, OnDestroy { private registrationFinishService: RegistrationFinishService, private validationService: ValidationService, private accountApiService: AccountApiService, + private loginStrategyService: LoginStrategyServiceAbstraction, + private logService: LogService, ) {} async ngOnInit() { @@ -90,8 +94,9 @@ export class RegistrationFinishComponent implements OnInit, OnDestroy { async handlePasswordFormSubmit(passwordInputResult: PasswordInputResult) { this.submitting = true; + let captchaBypassToken: string = null; try { - await this.registrationFinishService.finishRegistration( + captchaBypassToken = await this.registrationFinishService.finishRegistration( this.email, passwordInputResult, this.emailVerificationToken, @@ -102,14 +107,37 @@ export class RegistrationFinishComponent implements OnInit, OnDestroy { return; } + // Show acct created toast this.toastService.showToast({ variant: "success", title: null, - message: this.i18nService.t("newAccountCreated"), + message: this.i18nService.t("newAccountCreated2"), }); + // login with the new account + try { + const credentials = new PasswordLoginCredentials( + this.email, + passwordInputResult.password, + captchaBypassToken, + null, + ); + + await this.loginStrategyService.logIn(credentials); + + this.toastService.showToast({ + variant: "success", + title: null, + message: this.i18nService.t("youHaveBeenLoggedIn"), + }); + + await this.router.navigate(["/vault"]); + } catch (e) { + // If login errors, redirect to login page per product. Don't show error + this.logService.error("Error logging in after registration: ", e.message); + await this.router.navigate(["/login"], { queryParams: { email: this.email } }); + } this.submitting = false; - await this.router.navigate(["/login"], { queryParams: { email: this.email } }); } private async registerVerificationEmailClicked(email: string, emailVerificationToken: string) {