1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

[PM-4917, PM-8707, PM-9119] Persist login email memory through 2fa on browser (#9811)

* persist email memory through 2fa on browser

* fix tests

* fix desktop
This commit is contained in:
Jake Fink
2024-07-11 14:51:06 -04:00
committed by GitHub
parent 4f3760beae
commit 9c66b5bf9f
9 changed files with 60 additions and 45 deletions

View File

@@ -137,14 +137,16 @@ describe("LoginEmailService", () => {
expect(result).toEqual("initialEmail@bitwarden.com");
});
it("clears the email and rememberEmail after saving", async () => {
it("does not clear the email and rememberEmail after saving", async () => {
// Browser uses these values to maintain the email between login and 2fa components so
// we do not want to clear them too early.
sut.setEmail("userEmail@bitwarden.com");
sut.setRememberEmail(true);
await sut.saveEmailSettings();
const result = sut.getEmail();
expect(result).toBeNull();
expect(result).toBe("userEmail@bitwarden.com");
});
});
});

View File

@@ -73,6 +73,9 @@ export class LoginEmailService implements LoginEmailServiceAbstraction {
this.rememberEmail = value ?? false;
}
// Note: only clear values on successful login or you are sure they are not needed.
// Browser uses these values to maintain the email between login and 2fa components so
// we do not want to clear them too early.
clearValues() {
this.email = null;
this.rememberEmail = false;
@@ -89,12 +92,11 @@ export class LoginEmailService implements LoginEmailServiceAbstraction {
return storedEmail;
}
// Logging in with rememberEmail set to false will clear the stored email
// Saving with rememberEmail set to false will clear the stored email
if (this.rememberEmail) {
return this.email;
}
return null;
});
this.clearValues();
}
}