From 53820e1e3477c24059cb7681fe60608a271a8ea8 Mon Sep 17 00:00:00 2001 From: Alexey Titov Date: Mon, 17 Feb 2025 13:21:55 +0300 Subject: [PATCH] fix: add maxLength passwordPolicy in the getUserProfileApi --- src/login/KcContext/KcContext.ts | 2 ++ .../getUserProfileApi/getUserProfileApi.ts | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/login/KcContext/KcContext.ts b/src/login/KcContext/KcContext.ts index e07920af..48a73669 100644 --- a/src/login/KcContext/KcContext.ts +++ b/src/login/KcContext/KcContext.ts @@ -769,6 +769,8 @@ export declare namespace Validators { export type PasswordPolicies = { /** The minimum length of the password */ length?: number; + /** The maximum length of the password */ + maxLength?: number; /** The minimum number of digits required in the password */ digits?: number; /** The minimum number of lowercase characters required in the password */ diff --git a/src/login/lib/getUserProfileApi/getUserProfileApi.ts b/src/login/lib/getUserProfileApi/getUserProfileApi.ts index 0a695217..b8ce8774 100644 --- a/src/login/lib/getUserProfileApi/getUserProfileApi.ts +++ b/src/login/lib/getUserProfileApi/getUserProfileApi.ts @@ -509,6 +509,8 @@ function formStateSelector(params: { state: internal.State }): FormState { switch (error.source.name) { case "length": return hasLostFocusAtLeastOnce; + case "maxLength": + return hasLostFocusAtLeastOnce; case "digits": return hasLostFocusAtLeastOnce; case "lowerCase": @@ -967,6 +969,34 @@ function createGetErrors(params: { kcContext: KcContextLike_useGetErrors }) { }); } + check_password_policy_x: { + const policyName = "maxLength"; + + const policy = passwordPolicies[policyName]; + + if (!policy) { + break check_password_policy_x; + } + + const maxLength = policy; + + if (value.length <= maxLength) { + break check_password_policy_x; + } + + errors.push({ + advancedMsgArgs: [ + "invalidPasswordMaxLengthMessage" satisfies MessageKey_defaultSet, + `${maxLength}` + ] as const, + fieldIndex: undefined, + source: { + type: "passwordPolicy", + name: policyName + } + }); + } + check_password_policy_x: { const policyName = "digits";