Merge pull request #789 from EternalSide/fix/add-passwordPolicy-maxLength

fix: add maxLength passwordPolicy in the getUserProfileApi
This commit is contained in:
Joseph Garrone 2025-02-17 12:59:08 +01:00 committed by GitHub
commit 80988125e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -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 */

View File

@ -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";