fix(login): translate authentication and OTP strings (#12668)

Closes #12481
Closes #12226

# Which Problems Are Solved

Login V2 still contained several hardcoded authentication-method and OTP
strings, preventing them from following the selected locale or being
overridden through custom Login translations.

Additionally, the password-reset flow already referenced
`password.errors.passwordResetNotAllowed`, but the key was missing from
the Login V2 translations, causing the raw translation key to be
displayed when password reset is disabled.

# How the Problems Are Solved

* Replaced the hardcoded authentication-method labels with Login V2
translation keys.
* Replaced the OTP challenge and verification fallback messages with
translated values.
* Reused the existing `otp.verify.resendCode` translation for the resend
button's accessible label.
* Added `password.errors.passwordResetNotAllowed`.
* Added the new keys to all supported Login V2 locales and mirrored them
in `internal/query/v2-default.json` so frontend and API-provided default
translations remain consistent.
* Added unit coverage for the translated authentication labels and OTP
failure paths.

# How the Changes Are Tested

* `pnpm nx run @zitadel/login:test-unit`
* `pnpm nx run @zitadel/login:lint`
* `pnpm nx run @zitadel/login:build`
* `pnpm nx run-many --projects @zitadel/login @zitadel/client
@zitadel/proto --targets lint build test`
* Manually verified Login V2 with multiple locales, including
authentication-method labels, OTP failure fallbacks, and the disabled
password-reset flow.
This commit is contained in:
Matías Racedo
2026-09-03 06:01:34 +02:00
committed by GitHub
parent ee133d0fa4
commit 78be618357
24 changed files with 601 additions and 75 deletions
@@ -462,24 +462,46 @@ describe("resetPassword", () => {
let mockSearchUsers: any;
let mockGetLoginSettings: any;
let mockPasswordReset: any;
let mockGetTranslations: any;
beforeEach(async () => {
vi.clearAllMocks();
const { headers } = await import("next/headers");
const { getTranslations } = await import("next-intl/server");
const { getServiceConfig } = await import("../service-url");
const { getLoginSettings, passwordReset, searchUsers } = await import("../zitadel");
mockHeaders = vi.mocked(headers);
mockGetTranslations = vi.mocked(getTranslations);
mockGetServiceConfig = vi.mocked(getServiceConfig);
mockSearchUsers = vi.mocked(searchUsers);
mockGetLoginSettings = vi.mocked(getLoginSettings);
mockPasswordReset = vi.mocked(passwordReset);
mockHeaders.mockResolvedValue({ get: vi.fn(() => "example.com") });
mockGetTranslations.mockResolvedValue((key: string) => key);
mockGetServiceConfig.mockReturnValue({ serviceConfig: { baseUrl: "https://api.example.com" } });
});
test("should return translated password reset not allowed error when hidePasswordReset is true", async () => {
mockGetLoginSettings.mockResolvedValue({ hidePasswordReset: true });
mockGetTranslations.mockResolvedValue((key: string) => {
if (key === "errors.passwordResetNotAllowed") {
return "translated-password-reset-not-allowed";
}
return key;
});
const result = await resetPassword({
loginName: "[email protected]",
});
expect(result).toEqual({ error: "translated-password-reset-not-allowed" });
expect(mockSearchUsers).not.toHaveBeenCalled();
expect(mockPasswordReset).not.toHaveBeenCalled();
});
test("should return generic success when user not found and ignoreUnknownUsernames is true", async () => {
mockSearchUsers.mockResolvedValue({ result: [] });
mockGetLoginSettings.mockResolvedValue({ ignoreUnknownUsernames: true });