Skip to content

Commit

Permalink
feat(clerk-js,localizations): Nav to reset-password from pass-form …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Mark Pitsilos committed Mar 12, 2024
1 parent ef72c0a commit dba312a
Show file tree
Hide file tree
Showing 24 changed files with 47 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export const SignInFactorOnePasswordCard = (props: SignInFactorOnePasswordProps)
return setActive({ session: res.createdSessionId, beforeEmit: navigateAfterSignIn });
case 'needs_second_factor':
return navigate('../factor-two');
case 'needs_new_password':
return navigate('../reset-password');
default:
return console.error(clerkInvalidFAPIResponse(res.status, supportEmail));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,29 @@ describe('SignInFactorOne', () => {
});
});
});

it('redirects to `reset-password` if signIn requires a new password', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withEmailAddress();
f.withPassword();
f.withPreferredSignInStrategy({ strategy: 'password' });
f.startSignInWithPhoneNumber({ supportPassword: true });
});
fixtures.signIn.prepareFirstFactor.mockReturnValueOnce(Promise.resolve({} as SignInResource));

fixtures.signIn.attemptFirstFactor.mockReturnValueOnce(
Promise.resolve({ status: 'needs_new_password' } as SignInResource),
);

await runFakeTimers(async () => {
const { userEvent } = render(<SignInFactorOne />, { wrapper });
await userEvent.type(screen.getByLabelText('Password'), '123456');
await userEvent.click(screen.getByText('Continue'));
await waitFor(() => {
expect(fixtures.router.navigate).toHaveBeenCalledWith('../reset-password');
});
});
});
});

describe('Forgot Password', () => {
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/cs-CZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,7 @@ export const csCZ: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Obnovit heslo',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Vaše heslo bylo úspěšně změněno. Přihlašuji vás, prosím počkejte okamžik.',
title: 'Obnovit heslo',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/da-DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const daDK: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,7 @@ export const enUS: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/es-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ export const esES: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/es-MX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ export const esMX: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/fr-FR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,7 @@ export const frFR: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Réinitialiser',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage:
'Votre mot de passe a été modifié avec succès. Nous vous reconnectons, veuillez patienter un instant.',
title: 'Réinitialiser le mot de passe',
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/he-IL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ export const heIL: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'אפס סיסמה',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'הסיסמה שלך שונתה בהצלחה. מחבר אותך, אנא המתן רגע.',
title: 'אפס סיסמה',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/it-IT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const itIT: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/ko-KR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ export const koKR: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: '비밀번호 재설정',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: '비밀번호가 성공적으로 변경되었습니다. 로그인하는 중입니다. 잠시만 기다려주세요.',
title: '비밀번호 재설정',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/nl-NL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const nlNL: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/pl-PL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const plPL: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const ptBR: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Redefinir Senha',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Sua senha foi alterada com sucesso. Entrando, por favor aguarde um momento.',
title: 'Redefinir Senha',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/pt-PT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const ptPT: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Repor Palavra-passe',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'A sua palavra-passe foi alterada com sucesso. Entrando, por favor aguarde um momento.',
title: 'Repor Palavra-passe',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ export const ruRU: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Сбросить пароль',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Ваш пароль успешно изменен. Выполняется вход, подождите.',
title: 'Сбросить пароль',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/sk-SK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const skSK: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Obnoviť heslo',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Vaše heslo bolo úspešne zmenené. Prihlasujem vás, prosím počkajte okamžite.',
title: 'Obnoviť heslo',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/sv-SE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const svSE: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Reset Password',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
title: 'Set new password',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/tr-TR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const trTR: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Şifremi sıfırla',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Şifreniz başarıyla sıfırlandı. Oturumunuz açılıyor...',
title: 'Şifre sıfırlama',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/uk-UA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const ukUA: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Скинути пароль',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Ваш пароль успішно змінено. Виконується вхід, зачекайте.',
title: 'Скинути пароль',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/utils/enUS_v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ export const enUS_v4: any = {
title: 'Reset Password',
formButtonPrimary: 'Reset Password',
successMessage: 'Your password was successfully changed. Signing you in, please wait a moment.',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
},
resetPasswordMfa: {
detailsLabel: 'We need to verify your identity before resetting your password.',
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/vi-VN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,7 @@ export const viVN: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: 'Đặt lại mật khẩu',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: 'Mật khẩu của bạn đã được thay đổi thành công. Đang đăng nhập, vui lòng chờ một chút.',
title: 'Đặt lại mật khẩu',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ export const zhCN: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: '重置密码',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: '您的密码已成功更改。正在为您登录,请稍等。',
title: '重置密码',
},
Expand Down
3 changes: 1 addition & 2 deletions packages/localizations/src/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ export const zhTW: LocalizationResource = {
},
resetPassword: {
formButtonPrimary: '重設密碼',
requiredMessage:
'An account already exists with an unverified email address. Please reset your password for security.',
requiredMessage: 'For security reasons, it is required to reset your password.',
successMessage: '您的密碼已成功更改。正在為您登錄,請稍等。',
title: '重設密碼',
},
Expand Down

0 comments on commit dba312a

Please sign in to comment.