Skip to content

Commit 01264c4

Browse files
baxenmbot
andcommitted
Drop Replace's expected key on Create account
A sign-up is a new account, so it can never be the one Replace restarted for. Sign in and the timed-out wait's Continue keep the check. Co-authored-by: mbot <3754f8729004d95654c46dbab3129e4ab9ef05cc2534e2a3fbfc155983bd637b@buzz.block.builderlab.xyz> Signed-off-by: Bradley Axen <[email protected]>
1 parent 1a3e730 commit 01264c4

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎docs/identity.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ with no key, where Welcome back restores the account's key. The restart's note
7676
names that key (`buzz.sign-in-after-restart.expected.v1`): when the browser
7777
signs in to an account linked to another key, or to none, setup fails before it
7878
creates, links or restores any key, offering only **Use a different account**,
79-
which drops the expectation. With no backup of
79+
which drops the expectation, as **Create account** does: a new account can't
80+
be the one Replace restarted for. With no backup of
8081
the account's key, or no backups on this build or account (`unavailable`),
8182
Replace is not offered, since Welcome back could not restore it: the dialog says the account's
8283
key lives on another device and offers only **OK**. A backup status read that

‎src/features/identity/Welcome.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ export function Welcome({
468468
*/
469469
const signIn = async (create = false) => {
470470
signup.current = create;
471+
// A new account can't be the one Replace restarted for.
472+
if (create) expectedKey.current = undefined;
471473
const attempt = cancels.current;
472474
// A canceled attempt still settles here, possibly after a later sign-in
473475
// succeeded; it must not read that one's credential.

‎src/features/identity/identity.test.tsx‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8876,11 +8876,13 @@ it("a refused Replace from the open app fails setup, withdraws the sign-in after
88768876

88778877
const EXPECTED_AFTER_RESTART = "buzz.sign-in-after-restart.expected.v1";
88788878
/** The launch after Replace restarted Buzz for the account linked to `owned`. */
8879-
function launchAfterReplace(account: AccountFor) {
8879+
function launchAfterReplace(
8880+
account: AccountFor,
8881+
connect = vi.fn().mockResolvedValue(credential),
8882+
) {
88808883
missingKey();
88818884
localStorage.setItem(AFTER_RESTART, String(Date.now()));
88828885
localStorage.setItem(EXPECTED_AFTER_RESTART, owned.pubkey);
8883-
const connect = vi.fn().mockResolvedValue(credential);
88848886
const identity = createIdentity();
88858887
render(
88868888
<Welcome
@@ -8931,6 +8933,30 @@ it.each<[string, (other: string, bind: FirstRunAccount["bind"]) => AccountFor]>(
89318933
},
89328934
);
89338935

8936+
it("Create account in place of the sign-in after Replace's restart sets up the new account, without the wrong-account stop", async () => {
8937+
const bind = vi.fn((_pubkey: string) => Promise.resolve());
8938+
const connect = vi
8939+
.fn<(signal: AbortSignal, options: SignInOptions) => Promise<Credential>>()
8940+
// The automatic sign-in waits in the browser and is abandoned.
8941+
.mockReturnValueOnce(new Promise<Credential>(() => {}))
8942+
.mockResolvedValue(credential);
8943+
const { identity } = launchAfterReplace(unlinkedWith(bind), connect);
8944+
keyOnDevice(viewer, false);
8945+
const user = userEvent.setup();
8946+
await waitFor(() => expect(connect).toHaveBeenCalledTimes(1));
8947+
await user.click(
8948+
await screen.findByRole("button", { name: "Create account" }),
8949+
);
8950+
expect(
8951+
await screen.findByRole("heading", { name: "Connect to a community" }),
8952+
).toBeVisible();
8953+
expect(connect).toHaveBeenCalledTimes(2);
8954+
expect(connect.mock.calls[1]?.[1]).toEqual(createAccount);
8955+
expect(bind.mock.calls).toEqual([[viewer]]);
8956+
expect(screen.queryByText("Couldn’t finish setup")).toBeNull();
8957+
identity.dispose();
8958+
});
8959+
89348960
it("the sign-in after Replace's restart to the account it replaced the key for rests on Welcome back", async () => {
89358961
const { identity } = launchAfterReplace(linkedTo(owned.pubkey));
89368962
expect(

0 commit comments

Comments
 (0)