Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .changeset/password-reset-required-recovery.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@clerk/shared': minor
'@clerk/localizations': minor
'@clerk/ui': minor
---

`<SignIn />` and the reverification modal now guide users to reset their password when a password attempt returns `password_reset_required`. Until now, these users saw the API's English error message on the password step. They now see a "Password reset required" screen that offers "Reset your password" first, followed by their other sign-in methods. When the browser autofills the password on the first sign-in step, the user goes straight to the same screen without entering the password again.

Adds the localization keys `signIn.passwordResetRequired.title`, `reverification.passwordResetRequired.title`, `reverification.passwordResetRequired.subtitle__saveNewPassword` and `unstable__errors.password_reset_required`, with translations for every locale.
149 changes: 149 additions & 0 deletions integration/tests/password-reset-required.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { createClerkClient } from '@clerk/backend';
import type { Page } from '@playwright/test';
import { expect, test } from '@playwright/test';

import { appConfigs } from '../presets';
import { resolveInstanceKeys } from '../presets/envs';
import type { FakeUser } from '../testUtils';
import { createTestUtils, testAgainstRunningApps } from '../testUtils';
import { withRetry } from '../testUtils/retryableClerkClient';
import { createUserService } from '../testUtils/usersService';

const resetRequiredMessage = 'You need to reset your password before you can use it again.';

testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('password reset required @nextjs', ({ app }) => {
test.describe.configure({ mode: 'parallel' });

let providerUsers: ReturnType<typeof createUserService>;
const users: FakeUser[] = [];

test.beforeAll(async () => {
const providerKeys = await resolveInstanceKeys('oauth-provider');
providerUsers = createUserService(
withRetry(createClerkClient({ secretKey: providerKeys.sk, publishableKey: providerKeys.pk })),
);
});

test.afterAll(async () => {
const u = await createTestUtils({ app });
for (const user of users) {
await user.deleteIfExists();
await u.services.users.deleteIfExists({ email: user.email });
}
await app.teardown();
});

const signInWithOAuthToUserWithReservedEmail = async (u: Awaited<ReturnType<typeof createTestUtils>>) => {
const user = providerUsers.createFakeUser(test, { withUsername: true });
users.push(user);
await providerUsers.createBapiUser(user);
await u.services.clerk.users.createUser({
emailAddress: [user.email],
emailAddressIdentificationStatus: ['reserved'],
password: user.password,
});

await u.po.signIn.goTo();
await u.page.getByRole('button', { name: 'E2E OAuth Provider' }).click();
await u.page.getByText(/Sign in to .*oauth-provider/).waitFor();
await u.po.signIn.setIdentifier(user.email);
await u.po.signIn.continue();
await u.po.signIn.enterTestOtpCode();
await grantOAuthConsent(u.page);
await u.page.getByText('SignedIn').waitFor();
await u.po.expect.toBeSignedIn();

return user;
};

const signOut = async (u: Awaited<ReturnType<typeof createTestUtils>>) => {
await u.page.signOut();
await u.page.context().clearCookies();
};

test('password step offers the reset, which signs the user in', async ({ page, context }) => {
const u = await createTestUtils({ app, page, context });
const user = await signInWithOAuthToUserWithReservedEmail(u);
await signOut(u);

await u.po.signIn.goTo();
await u.po.signIn.setIdentifier(user.email);
await u.po.signIn.continue();
await u.po.signIn.setPassword(user.password);
await u.po.signIn.continue();

await expect(u.page.getByText('Password reset required')).toBeVisible();
await expect(u.page.getByText(resetRequiredMessage)).toBeVisible();
await expect(u.po.signIn.getAltMethodsEmailCodeButton()).toBeVisible();
await expect(u.page.getByText('Back', { exact: true })).toBeHidden();

await u.po.signIn.getResetPassword().click();
await u.po.signIn.enterTestOtpCode();
const newPassword = `${user.password}_reset`;
await u.po.signIn.setPassword(newPassword);
await u.po.signIn.setPasswordConfirmation(newPassword);
await u.po.signIn.getResetPassword().click();
await u.po.expect.toBeSignedIn();
});

test('password entered on the first step goes straight to the reset', async ({ page, context }) => {
const u = await createTestUtils({ app, page, context });
const user = await signInWithOAuthToUserWithReservedEmail(u);
await signOut(u);

await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword({
email: user.email,
password: user.password,
waitForSession: false,
});

await expect(u.page.getByText('Password reset required')).toBeVisible();
await expect(u.page.getByText(resetRequiredMessage)).toBeVisible();
await expect(u.po.signIn.getPasswordInput()).toBeHidden();
await expect(u.po.signIn.getResetPassword()).toBeVisible();
await u.po.expect.toBeSignedOut();
});

test('reverification resets the password while saving a new one', async ({ page, context }) => {
const u = await createTestUtils({ app, page, context });
const user = await signInWithOAuthToUserWithReservedEmail(u);

await u.po.userProfile.goTo();
await u.po.userProfile.waitForMounted();
await u.po.userProfile.switchToSecurityTab();
await u.page.waitForFunction(async () => {
await window.Clerk.session.startVerification({ level: 'first_factor' });
});

await u.page.getByRole('button', { name: /update password/i }).click();
const newPassword = `${user.password}_new`;
await u.page.locator('input[name=newPassword]').fill(newPassword);
await u.page.locator('input[name=confirmPassword]').fill(newPassword);
await u.page.getByRole('button', { name: /^save$/i }).click();

await u.po.userVerification.waitForMounted();
await u.po.userVerification.setPassword(user.password);
await u.po.userVerification.continue();

await expect(u.page.getByText('Password reset required')).toBeVisible();
await expect(
u.page.getByText("Your current password needs to be reset. Confirm it's you to save your new password."),
).toBeVisible();

await u.po.userVerification.getAltMethodsEmailCodeButton().first().click();
await u.po.userVerification.enterTestOtpCode();
await u.po.userVerification.waitForClosed();

await signOut(u);
await u.po.signIn.goTo();
await u.po.signIn.signInWithEmailAndInstantPassword({ email: user.email, password: newPassword });
await u.po.expect.toBeSignedIn();
});
});

const grantOAuthConsent = async (page: Page) => {
const allowAccessButton = page.getByRole('button', { name: 'Allow' });
await expect(allowAccessButton).toBeVisible();
await allowAccessButton.click();
};
8 changes: 8 additions & 0 deletions packages/localizations/src/ar-SA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,10 @@ export const arSA: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword: 'يجب إعادة تعيين كلمة المرور الحالية. أكّد هويتك لحفظ كلمة المرور الجديدة.',
title: 'يلزم إعادة تعيين كلمة المرور',
},
phoneCode: {
formTitle: undefined,
resendButton: undefined,
Expand Down Expand Up @@ -1830,6 +1834,9 @@ export const arSA: LocalizationResource = {
passwordPwned: {
title: 'كلمة المرور غير آمنة',
},
passwordResetRequired: {
title: 'يلزم إعادة تعيين كلمة المرور',
},
passwordUntrusted: {
title: undefined,
},
Expand Down Expand Up @@ -2186,6 +2193,7 @@ export const arSA: LocalizationResource = {
password_confirmation_attempts_remaining: 'كلمة المرور غير صحيحة. عدد المحاولات المتبقية: {{remainingAttempts}}.',
password_confirmation_session_ended:
'انتهت جلستك لأنك وصلت إلى الحد الأقصى لمحاولات تأكيد كلمة المرور. تم قفل حسابك. يرجى التواصل مع الدعم لإلغاء قفله.',
password_reset_required: 'يجب عليك إعادة تعيين كلمة المرور قبل أن تتمكن من استخدامها مرة أخرى.',
phone_number_exists: 'هذا الرقم مأخوذ الرجاء أختيار رقم آخر',
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
8 changes: 8 additions & 0 deletions packages/localizations/src/be-BY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1661,6 +1661,10 @@ export const beBY: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword: 'Ваш бягучы пароль трэба скінуць. Пацвердзіце, што гэта вы, каб захаваць новы пароль.',
title: 'Патрабуецца скід пароля',
},
phoneCode: {
formTitle: 'Увядзіце код, які быў адпраўлены на ваш тэлефон.',
resendButton: 'Пераадправіць код на тэлефон',
Expand Down Expand Up @@ -1838,6 +1842,9 @@ export const beBY: LocalizationResource = {
passwordPwned: {
title: 'Пароль быў узламаны',
},
passwordResetRequired: {
title: 'Патрабуецца скід пароля',
},
passwordUntrusted: {
title: undefined,
},
Expand Down Expand Up @@ -2197,6 +2204,7 @@ export const beBY: LocalizationResource = {
password_confirmation_attempts_remaining: 'Няправільны пароль. Засталося спроб: {{remainingAttempts}}.',
password_confirmation_session_ended:
'Ваш сеанс завершаны, бо вы дасягнулі ліміту спроб пацвярджэння пароля. Ваш уліковы запіс заблакаваны. Звярніцеся ў службу падтрымкі, каб разблакаваць яго.',
password_reset_required: 'Вам трэба скінуць пароль, перш чым вы зможаце выкарыстоўваць яго зноў.',
phone_number_exists: 'Гэты нумар тэлефона ўжо заняты. Калі ласка, паспрабуйце іншы.',
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
9 changes: 9 additions & 0 deletions packages/localizations/src/bg-BG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,11 @@ export const bgBG: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword:
'Текущата ви парола трябва да бъде нулирана. Потвърдете, че сте вие, за да запазите новата си парола.',
title: 'Необходимо е нулиране на паролата',
},
phoneCode: {
formTitle: 'Enter the verification code sent to your phone number.',
resendButton: "Didn't receive the code? Resend it.",
Expand Down Expand Up @@ -1835,6 +1840,9 @@ export const bgBG: LocalizationResource = {
passwordPwned: {
title: undefined,
},
passwordResetRequired: {
title: 'Необходимо е нулиране на паролата',
},
passwordUntrusted: {
title: undefined,
},
Expand Down Expand Up @@ -2191,6 +2199,7 @@ export const bgBG: LocalizationResource = {
password_confirmation_attempts_remaining: 'Грешна парола. Остават ви {{remainingAttempts}} опита.',
password_confirmation_session_ended:
'Сесията ви приключи, защото достигнахте лимита на опитите за потвърждение на паролата. Акаунтът ви е заключен. Свържете се с поддръжката, за да го отключите.',
password_reset_required: 'Трябва да нулирате паролата си, преди да можете да я използвате отново.',
phone_number_exists: 'Този телефонен номер е зает. Моля, опитайте с друг.',
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
9 changes: 9 additions & 0 deletions packages/localizations/src/bn-IN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,11 @@ export const bnIN: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword:
'আপনার বর্তমান পাসওয়ার্ড রিসেট করতে হবে। আপনার নতুন পাসওয়ার্ড সংরক্ষণ করতে নিশ্চিত করুন যে এটি আপনি।',
title: 'পাসওয়ার্ড রিসেট করা প্রয়োজন',
},
phoneCode: {
formTitle: 'যাচাইকরণ কোড',
resendButton: 'কোনো কোড পাননি? পুনরায় পাঠান',
Expand Down Expand Up @@ -1843,6 +1848,9 @@ export const bnIN: LocalizationResource = {
passwordPwned: {
title: 'পাসওয়ার্ড সমঝোতা হয়েছে',
},
passwordResetRequired: {
title: 'পাসওয়ার্ড রিসেট করা প্রয়োজন',
},
passwordUntrusted: {
title: 'পাসওয়ার্ড অবিশ্বস্ত',
},
Expand Down Expand Up @@ -2215,6 +2223,7 @@ export const bnIN: LocalizationResource = {
password_confirmation_attempts_remaining: 'ভুল পাসওয়ার্ড। আপনার আর {{remainingAttempts}}টি প্রচেষ্টা বাকি আছে।',
password_confirmation_session_ended:
'পাসওয়ার্ড নিশ্চিতকরণের প্রচেষ্টার সীমায় পৌঁছানোর কারণে আপনার সেশন শেষ হয়েছে। আপনার অ্যাকাউন্ট লক করা হয়েছে। এটি আনলক করতে সাপোর্টের সাথে যোগাযোগ করুন।',
password_reset_required: 'আবার ব্যবহার করার আগে আপনাকে আপনার পাসওয়ার্ড রিসেট করতে হবে।',
phone_number_exists: 'এই ফোন নম্বর ব্যবহৃত হয়েছে। দয়া করে অন্য একটি ব্যবহার করুন।',
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
9 changes: 9 additions & 0 deletions packages/localizations/src/ca-ES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1666,6 +1666,11 @@ export const caES: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword:
'Cal restablir la teva contrasenya actual. Confirma que ets tu per desar la nova contrasenya.',
title: 'Cal restablir la contrasenya',
},
phoneCode: {
formTitle: 'Introdueix el codi enviat al teu telèfon.',
resendButton: 'Reenvia codi',
Expand Down Expand Up @@ -1843,6 +1848,9 @@ export const caES: LocalizationResource = {
passwordPwned: {
title: 'La teva contrasenya ha estat compromesa',
},
passwordResetRequired: {
title: 'Cal restablir la contrasenya',
},
passwordUntrusted: {
title: undefined,
},
Expand Down Expand Up @@ -2204,6 +2212,7 @@ export const caES: LocalizationResource = {
password_confirmation_attempts_remaining: 'Contrasenya incorrecta. Et queden {{remainingAttempts}} intents.',
password_confirmation_session_ended:
"La teva sessió ha finalitzat perquè has arribat al límit d'intents de confirmació de la contrasenya. El teu compte està bloquejat. Contacta amb el suport per desbloquejar-lo.",
password_reset_required: 'Has de restablir la contrasenya abans de poder tornar-la a utilitzar.',
phone_number_exists: "Aquest número de telèfon ja està en ús. Si us plau, prova'n un altre.",
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
9 changes: 9 additions & 0 deletions packages/localizations/src/cs-CZ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,11 @@ export const csCZ: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword:
'Vaše současné heslo je potřeba resetovat. Potvrďte, že jste to vy, abyste mohli uložit nové heslo.',
title: 'Je vyžadován reset hesla',
},
phoneCode: {
formTitle: 'Ověřovací kód',
resendButton: 'Neobdrželi jste kód? Znovu poslat',
Expand Down Expand Up @@ -1842,6 +1847,9 @@ export const csCZ: LocalizationResource = {
passwordPwned: {
title: 'Heslo kompromitováno',
},
passwordResetRequired: {
title: 'Je vyžadován reset hesla',
},
passwordUntrusted: {
title: undefined,
},
Expand Down Expand Up @@ -2202,6 +2210,7 @@ export const csCZ: LocalizationResource = {
password_confirmation_attempts_remaining: 'Nesprávné heslo. Počet zbývajících pokusů: {{remainingAttempts}}.',
password_confirmation_session_ended:
'Vaše relace byla ukončena, protože jste dosáhli limitu pokusů o potvrzení hesla. Váš účet je uzamčen. Pro jeho odemčení kontaktujte podporu.',
password_reset_required: 'Než budete moci heslo znovu použít, musíte ho resetovat.',
phone_number_exists: 'Toto telefonní číslo se používá. Zkuste prosím jiný.',
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
9 changes: 9 additions & 0 deletions packages/localizations/src/da-DK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,11 @@ export const daDK: LocalizationResource = {
subtitle__saveNewPassword: undefined,
title: undefined,
},
passwordResetRequired: {
subtitle__saveNewPassword:
'Din nuværende adgangskode skal nulstilles. Bekræft, at det er dig, for at gemme din nye adgangskode.',
title: 'Nulstilling af adgangskode påkrævet',
},
phoneCode: {
formTitle: undefined,
resendButton: undefined,
Expand Down Expand Up @@ -1832,6 +1837,9 @@ export const daDK: LocalizationResource = {
passwordPwned: {
title: 'Sikkerhedsadvarsel',
},
passwordResetRequired: {
title: 'Nulstilling af adgangskode påkrævet',
},
passwordUntrusted: {
title: undefined,
},
Expand Down Expand Up @@ -2187,6 +2195,7 @@ export const daDK: LocalizationResource = {
password_confirmation_attempts_remaining: 'Forkert adgangskode. Du har {{remainingAttempts}} forsøg tilbage.',
password_confirmation_session_ended:
'Din session er afsluttet, fordi du har nået grænsen for forsøg på at bekræfte adgangskoden. Din konto er låst. Kontakt support for at få den låst op.',
password_reset_required: 'Du skal nulstille din adgangskode, før du kan bruge den igen.',
phone_number_exists: 'Dette telefonnummer er allerede taget. Prøv et andet.',
protect_check_aborted: undefined,
protect_check_already_resolved: undefined,
Expand Down
Loading
Loading