Skip to content

Commit a4b140d

Browse files
author
Mark Pitsilos
committed
feat(clerk-js,localizations): Nav to reset-password from pass-form if sign_in.needs_new_password
If password_settings.enforce_on_sign_in is true, then it will be possible for a password sign-in to succeed but require a new password that conforms to updated password requirements. Hence, if sign_in.needs_new_password is true, the password form will navigate to reset-password. Since we are reusing a flow initially created for resetting passwords after an oauth flow, the error message has been made more generic.
1 parent 9272006 commit a4b140d

File tree

25 files changed

+53
-44
lines changed

25 files changed

+53
-44
lines changed

.changeset/four-ties-yawn.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@clerk/localizations': minor
3+
'@clerk/clerk-js': minor
4+
---
5+
6+
Navigate to reset-password from the password form if password_settings.enforce_on_sign_in is enabled and sign_in.needs_new_password is true.

packages/clerk-js/src/ui/components/SignIn/SignInFactorOnePasswordCard.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps)
7171
return setActive({ session: res.createdSessionId, beforeEmit: navigateAfterSignIn });
7272
case 'needs_second_factor':
7373
return navigate('../factor-two');
74+
case 'needs_new_password':
75+
return navigate('../reset-password');
7476
default:
7577
return console.error(clerkInvalidFAPIResponse(res.status, supportEmail));
7678
}

packages/clerk-js/src/ui/components/SignIn/__tests__/SignInFactorOne.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,29 @@ describe('SignInFactorOne', () => {
227227
});
228228
});
229229
});
230+
231+
it('redirects to `reset-password` if signIn requires a new password', async () => {
232+
const { wrapper, fixtures } = await createFixtures(f => {
233+
f.withEmailAddress();
234+
f.withPassword();
235+
f.withPreferredSignInStrategy({ strategy: 'password' });
236+
f.startSignInWithPhoneNumber({ supportPassword: true });
237+
});
238+
fixtures.signIn.prepareFirstFactor.mockReturnValueOnce(Promise.resolve({} as SignInResource));
239+
240+
fixtures.signIn.attemptFirstFactor.mockReturnValueOnce(
241+
Promise.resolve({ status: 'needs_new_password' } as SignInResource),
242+
);
243+
244+
await runFakeTimers(async () => {
245+
const { userEvent } = render(<SignInFactorOne />, { wrapper });
246+
await userEvent.type(screen.getByLabelText('Password'), '123456');
247+
await userEvent.click(screen.getByText('Continue'));
248+
await waitFor(() => {
249+
expect(fixtures.router.navigate).toHaveBeenCalledWith('../reset-password');
250+
});
251+
});
252+
});
230253
});
231254

232255
describe('Forgot Password', () => {

packages/localizations/src/cs-CZ.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ export const csCZ: LocalizationResource = {
370370
},
371371
resetPassword: {
372372
formButtonPrimary: 'Obnovit heslo',
373-
requiredMessage:
374-
'An account already exists with an unverified email address. Please reset your password for security.',
373+
requiredMessage: 'For security reasons, it is required to reset your password.',
375374
successMessage: 'Vaše heslo bylo úspěšně změněno. Přihlašuji vás, prosím počkejte okamžik.',
376375
title: 'Obnovit heslo',
377376
},

packages/localizations/src/da-DK.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ export const daDK: LocalizationResource = {
371371
},
372372
resetPassword: {
373373
formButtonPrimary: 'Reset Password',
374-
requiredMessage:
375-
'An account already exists with an unverified email address. Please reset your password for security.',
374+
requiredMessage: 'For security reasons, it is required to reset your password.',
376375
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
377376
title: 'Set new password',
378377
},

packages/localizations/src/en-US.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,7 @@ export const enUS: LocalizationResource = {
360360
},
361361
resetPassword: {
362362
formButtonPrimary: 'Reset Password',
363-
requiredMessage:
364-
'An account already exists with an unverified email address. Please reset your password for security.',
363+
requiredMessage: 'For security reasons, it is required to reset your password.',
365364
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
366365
title: 'Set new password',
367366
},

packages/localizations/src/es-ES.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ export const esES: LocalizationResource = {
372372
},
373373
resetPassword: {
374374
formButtonPrimary: 'Reset Password',
375-
requiredMessage:
376-
'An account already exists with an unverified email address. Please reset your password for security.',
375+
requiredMessage: 'For security reasons, it is required to reset your password.',
377376
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
378377
title: 'Set new password',
379378
},

packages/localizations/src/es-MX.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ export const esMX: LocalizationResource = {
372372
},
373373
resetPassword: {
374374
formButtonPrimary: 'Reset Password',
375-
requiredMessage:
376-
'An account already exists with an unverified email address. Please reset your password for security.',
375+
requiredMessage: 'For security reasons, it is required to reset your password.',
377376
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
378377
title: 'Set new password',
379378
},

packages/localizations/src/fr-FR.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ export const frFR: LocalizationResource = {
372372
},
373373
resetPassword: {
374374
formButtonPrimary: 'Réinitialiser',
375-
requiredMessage:
376-
'An account already exists with an unverified email address. Please reset your password for security.',
375+
requiredMessage: 'For security reasons, it is required to reset your password.',
377376
successMessage:
378377
'Votre mot de passe a été modifié avec succès. Nous vous reconnectons, veuillez patienter un instant.',
379378
title: 'Réinitialiser le mot de passe',

packages/localizations/src/he-IL.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,7 @@ export const heIL: LocalizationResource = {
368368
},
369369
resetPassword: {
370370
formButtonPrimary: 'אפס סיסמה',
371-
requiredMessage:
372-
'An account already exists with an unverified email address. Please reset your password for security.',
371+
requiredMessage: 'For security reasons, it is required to reset your password.',
373372
successMessage: 'הסיסמה שלך שונתה בהצלחה. מחבר אותך, אנא המתן רגע.',
374373
title: 'אפס סיסמה',
375374
},

0 commit comments

Comments
 (0)