@keycloakify/keycloak-admin-ui
Version:
<p align="center"> <img src="https://github.com/user-attachments/assets/a6aaebbd-8f59-474d-9827-c282f4527aca"> </p> <p align="center"> <i>Repackaged Keycloak Admin UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-adm
38 lines (31 loc) • 1.19 kB
text/typescript
/* eslint-disable */
// @ts-nocheck
import { UserProfileAttributeMetadata } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata";
export function isRequiredAttribute({
required,
validators,
}: UserProfileAttributeMetadata): boolean {
// Check if required is true or if the validators include a validation that would make the attribute implicitly required.
return required || hasRequiredValidators(validators);
}
/**
* Checks whether the given validators include a validation that would make the attribute implicitly required.
*/
function hasRequiredValidators(
validators?: UserProfileAttributeMetadata["validators"],
): boolean {
// If we don't have any validators, the attribute is not required.
if (!validators) {
return false;
}
// If the 'length' validator is defined and has a minimal length greater than zero the attribute is implicitly required.
// We have to do a lot of defensive coding here, because we don't have type information for the validators.
if (
"length" in validators &&
"min" in validators.length &&
typeof validators.length.min === "number"
) {
return validators.length.min > 0;
}
return false;
}