Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit eb43f34

Browse files
authored
Fix the problem that the password reset email has to be confirmed twice (#9926)
1 parent 576d103 commit eb43f34

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/components/structures/auth/ForgotPassword.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ export default class ForgotPassword extends React.Component<Props, State> {
262262

263263
try {
264264
await this.reset.setNewPassword(this.state.password);
265+
this.setState({ phase: Phase.Done });
266+
return;
265267
} catch (err: any) {
266268
if (err.httpStatus !== 401) {
267269
// 401 = waiting for email verification, else unknown error

test/components/structures/auth/ForgotPassword-test.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,37 @@ describe("<ForgotPassword>", () => {
288288
});
289289
});
290290

291+
describe("and confirm the email link and submitting the new password", () => {
292+
beforeEach(async () => {
293+
// fake link confirmed by resolving client.setPassword instead of raising an error
294+
mocked(client.setPassword).mockResolvedValue({});
295+
await click(screen.getByText("Reset password"));
296+
});
297+
298+
it("should send the new password (once)", () => {
299+
expect(client.setPassword).toHaveBeenCalledWith(
300+
{
301+
type: "m.login.email.identity",
302+
threepid_creds: {
303+
client_secret: expect.any(String),
304+
sid: testSid,
305+
},
306+
threepidCreds: {
307+
client_secret: expect.any(String),
308+
sid: testSid,
309+
},
310+
},
311+
testPassword,
312+
false,
313+
);
314+
315+
// be sure that the next attempt to set the password would have been sent
316+
jest.advanceTimersByTime(3000);
317+
// it should not retry to set the password
318+
expect(client.setPassword).toHaveBeenCalledTimes(1);
319+
});
320+
});
321+
291322
describe("and submitting it", () => {
292323
beforeEach(async () => {
293324
await click(screen.getByText("Reset password"));

0 commit comments

Comments
 (0)