keycloakify 4.0.0 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +60 -23
- package/lib/getKcContext/index.d.ts +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/useFormValidationSlice.d.ts +1 -0
- package/lib/useFormValidationSlice.js +5 -6
- package/lib/useFormValidationSlice.js.map +1 -1
- package/package.json +3 -3
- package/src/lib/getKcContext/index.ts +1 -1
- package/src/lib/index.ts +1 -0
- package/src/lib/useFormValidationSlice.tsx +69 -65
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
### **4.2.2** (2021-10-27)
|
2
|
+
|
3
|
+
- Replace 'path' by 'browserify-path' #47
|
4
|
+
|
5
|
+
### **4.2.1** (2021-10-26)
|
6
|
+
|
7
|
+
- useFormValidationSlice: update when params have changed
|
8
|
+
- Explains that the password can't be validated
|
9
|
+
|
10
|
+
## **4.2.0** (2021-10-26)
|
11
|
+
|
12
|
+
- Export types definitions for Attribue and Validator
|
13
|
+
|
14
|
+
## **4.1.0** (2021-10-26)
|
15
|
+
|
16
|
+
- Document what's new in v4
|
17
|
+
|
1
18
|
# **4.0.0** (2021-10-26)
|
2
19
|
|
3
20
|
- fix RegisterUserProfile password confirmation field
|
package/README.md
CHANGED
@@ -20,30 +20,10 @@
|
|
20
20
|
<img src="https://user-images.githubusercontent.com/6702424/110260457-a1c3d380-7fac-11eb-853a-80459b65626b.png">
|
21
21
|
</p>
|
22
22
|
|
23
|
-
**NEW in
|
23
|
+
**NEW in v4**
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
[when passing params from the app to the login page](https://github.com/InseeFrLab/keycloakify#implement-context-persistence-optional).
|
28
|
-
|
29
|
-
**NEW in v2.5**
|
30
|
-
|
31
|
-
- User Profile ([`register-user-profile.ftl`](https://github.com/InseeFrLab/keycloakify/blob/main/src/lib/components/RegisterUserProfile.tsx))
|
32
|
-
is now supported! 🎉
|
33
|
-
It enables to [define, from the admin console](https://user-images.githubusercontent.com/6702424/136872461-1f5b64ef-d2ef-4c6b-bb8d-07d4729552b3.png),
|
34
|
-
what information you want to collect on your users in the register page and to validate inputs
|
35
|
-
[**on the frontend**, in realtime](https://github.com/InseeFrLab/keycloakify/blob/6dca6a93d8cfe634ee4d8574ad0c091641220092/src/lib/getKcContext/KcContextBase.ts#L225-L261)!
|
36
|
-
NOTE: User profile is only available in Keycloak 15 and it's a beta feature that
|
37
|
-
[needs to be enabled when launching keycloak](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/bin/build-keycloak-theme/build-keycloak-theme.ts#L116-L117) and [enabled in the console](https://user-images.githubusercontent.com/6702424/136874428-b071d614-c7f7-440d-9b2e-670faadc0871.png).
|
38
|
-
- Feature [Use advanced message](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/lib/i18n/useKcMessage.tsx#L53-L66)
|
39
|
-
and [`messagesPerFields`](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/lib/getKcContext/KcContextBase.ts#L70-L75) (implementation [here](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/bin/build-keycloak-theme/generateFtl/common.ftl#L130-L189))
|
40
|
-
- Test container now uses Keycloak version `15.0.2`.
|
41
|
-
|
42
|
-
**NEW in v2**
|
43
|
-
|
44
|
-
- It's now possible to implement custom `.ftl` pages.
|
45
|
-
- Support for Keycloak plugins that introduce non standard ftl values.
|
46
|
-
(Like for example [this plugin](https://github.com/micedre/keycloak-mail-whitelisting) that define `authorizedMailDomains` in `register.ftl`).
|
25
|
+
- Out of the box [frontend form validation](#user-profile-and-frontend-form-validation) 🥳
|
26
|
+
- Improvements (and breaking changes in `import { useKcMessage } from "keycloakify"`.
|
47
27
|
|
48
28
|
# Motivations
|
49
29
|
|
@@ -85,6 +65,7 @@ If you already have a Keycloak custom theme, it can be easily ported to Keycloak
|
|
85
65
|
- [Advanced pages configuration](#advanced-pages-configuration)
|
86
66
|
- [Hot reload](#hot-reload)
|
87
67
|
- [Enable loading in a blink of an eye of login pages ⚡ (--external-assets)](#enable-loading-in-a-blink-of-an-eye-of-login-pages----external-assets)
|
68
|
+
- [User profile and frontend form validation](#user-profile-and-frontend-form-validation)
|
88
69
|
- [Support for Terms and conditions](#support-for-terms-and-conditions)
|
89
70
|
- [Some pages still have the default theme. Why?](#some-pages-still-have-the-default-theme-why)
|
90
71
|
- [GitHub Actions](#github-actions)
|
@@ -98,6 +79,11 @@ If you already have a Keycloak custom theme, it can be easily ported to Keycloak
|
|
98
79
|
- [About the errors related to `objectToJson` in Keycloak logs.](#about-the-errors-related-to-objecttojson-in-keycloak-logs)
|
99
80
|
- [Adding custom message (to `i18n/useKcMessage.tsx`)](#adding-custom-message-to-i18nusekcmessagetsx)
|
100
81
|
- [Email domain whitelist](#email-domain-whitelist)
|
82
|
+
- [Changelog highlights](#changelog-highlights)
|
83
|
+
- [v4](#v4)
|
84
|
+
- [v3](#v3)
|
85
|
+
- [v2.5](#v25)
|
86
|
+
- [v2](#v2)
|
101
87
|
|
102
88
|
# Requirements
|
103
89
|
|
@@ -313,6 +299,32 @@ performance boost if you jump through those hoops:
|
|
313
299
|
|
314
300
|
Checkout a complete setup [here](https://github.com/garronej/keycloakify-demo-app#about-keycloakify)
|
315
301
|
|
302
|
+
# User profile and frontend form validation
|
303
|
+
|
304
|
+
<p align="center">
|
305
|
+
<a href="https://github.com/InseeFrLab/keycloakify/releases/download/v0.0.1/keycloakify_fontend_validation.mp4">
|
306
|
+
<img src="https://user-images.githubusercontent.com/6702424/138880146-6fef3280-c4a5-46d2-bbb3-8b9598c057a5.gif">
|
307
|
+
</a>
|
308
|
+
</p>
|
309
|
+
|
310
|
+
User Profile is a Keycloak feature that enables to
|
311
|
+
[define, from the admin console](https://user-images.githubusercontent.com/6702424/136872461-1f5b64ef-d2ef-4c6b-bb8d-07d4729552b3.png),
|
312
|
+
what information you want to collect on your users in the register page and to validate inputs
|
313
|
+
[**on the frontend**, in realtime](https://github.com/InseeFrLab/keycloakify/blob/6dca6a93d8cfe634ee4d8574ad0c091641220092/src/lib/getKcContext/KcContextBase.ts#L225-L261)!
|
314
|
+
|
315
|
+
NOTE: User profile is only available in Keycloak 15 and it's a beta feature that
|
316
|
+
[needs to be enabled when launching keycloak](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/bin/build-keycloak-theme/build-keycloak-theme.ts#L116-L117)
|
317
|
+
and [enabled in the console](https://user-images.githubusercontent.com/6702424/136874428-b071d614-c7f7-440d-9b2e-670faadc0871.png).
|
318
|
+
|
319
|
+
Keycloakify, in [`register-user-profile.ftl`](https://github.com/InseeFrLab/keycloakify/blob/main/src/lib/components/RegisterUserProfile.tsx),
|
320
|
+
provides frontend validation out of the box.
|
321
|
+
|
322
|
+
For implementing your own `register-user-profile.ftl` page, you can use [`import { useFormValidationSlice } from "keycloakify";`](https://github.com/InseeFrLab/keycloakify/blob/main/src/lib/useFormValidationSlice.tsx).
|
323
|
+
Find usage example [`here`](https://github.com/InseeFrLab/keycloakify/blob/d3a07edfcb3739e30032dc96fc2a55944dfc3387/src/lib/components/RegisterUserProfile.tsx#L79-L112).
|
324
|
+
|
325
|
+
As for right now [it's not possible to define a pattern for the password](https://keycloak.discourse.group/t/make-password-policies-available-to-freemarker/11632)
|
326
|
+
from the admin console. You can however pass validators for it to the `useFormValidationSlice` function.
|
327
|
+
|
316
328
|
# Support for Terms and conditions
|
317
329
|
|
318
330
|
[Many organizations have a requirement that when a new user logs in for the first time, they need to agree to the terms and conditions of the website.](https://www.keycloak.org/docs/4.8/server_admin/#terms-and-conditions).
|
@@ -455,3 +467,28 @@ This approach is a bit hacky as it doesn't provide type safety but it works.
|
|
455
467
|
|
456
468
|
If you want to restrict the emails domain that can register, you can use [this plugin](https://github.com/micedre/keycloak-mail-whitelisting)
|
457
469
|
and `kcRegisterContext["authorizedMailDomains"]` to validate on.
|
470
|
+
|
471
|
+
# Changelog highlights
|
472
|
+
|
473
|
+
## v4
|
474
|
+
|
475
|
+
- Out of the box [frontend form validation](#user-profile-and-frontend-form-validation) 🥳
|
476
|
+
- Improvements (and breaking changes in `import { useKcMessage } from "keycloakify"`.
|
477
|
+
|
478
|
+
## v3
|
479
|
+
|
480
|
+
No breaking changes except that `@emotion/react`, [`tss-react`](https://www.npmjs.com/package/tss-react) and [`powerhooks`](https://www.npmjs.com/package/powerhooks) are now `peerDependencies` instead of being just dependencies.
|
481
|
+
It's important to avoid problem when using `keycloakify` alongside [`mui`](https://mui.com) and
|
482
|
+
[when passing params from the app to the login page](https://github.com/InseeFrLab/keycloakify#implement-context-persistence-optional).
|
483
|
+
|
484
|
+
## v2.5
|
485
|
+
|
486
|
+
- Feature [Use advanced message](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/lib/i18n/useKcMessage.tsx#L53-L66)
|
487
|
+
and [`messagesPerFields`](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/lib/getKcContext/KcContextBase.ts#L70-L75) (implementation [here](https://github.com/InseeFrLab/keycloakify/blob/59f106bf9e210b63b190826da2bf5f75fc8b7644/src/bin/build-keycloak-theme/generateFtl/common.ftl#L130-L189))
|
488
|
+
- Test container now uses Keycloak version `15.0.2`.
|
489
|
+
|
490
|
+
## v2
|
491
|
+
|
492
|
+
- It's now possible to implement custom `.ftl` pages.
|
493
|
+
- Support for Keycloak plugins that introduce non standard ftl values.
|
494
|
+
(Like for example [this plugin](https://github.com/micedre/keycloak-mail-whitelisting) that define `authorizedMailDomains` in `register.ftl`).
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export type { KcContextBase } from "./KcContextBase";
|
1
|
+
export type { KcContextBase, Attribute, Validators } from "./KcContextBase";
|
2
2
|
export { getKcContext } from "./getKcContext";
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -24,5 +24,6 @@ __exportStar(require("./components/Error"), exports);
|
|
24
24
|
__exportStar(require("./components/LoginResetPassword"), exports);
|
25
25
|
__exportStar(require("./components/LoginVerifyEmail"), exports);
|
26
26
|
__exportStar(require("./keycloakJsAdapter"), exports);
|
27
|
+
__exportStar(require("./useFormValidationSlice"), exports);
|
27
28
|
__exportStar(require("./tools/assert"), exports);
|
28
29
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B;AAE/B,uDAAqC;AACrC,0DAAwC;AACxC,sDAAoC;AACpC,0DAAwC;AAExC,uDAAqC;AACrC,qDAAmC;AACnC,wDAAsC;AACtC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,kEAAgD;AAChD,gEAA8C;AAC9C,sDAAoC;
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B;AAE/B,uDAAqC;AACrC,0DAAwC;AACxC,sDAAoC;AACpC,0DAAwC;AAExC,uDAAqC;AACrC,qDAAmC;AACnC,wDAAsC;AACtC,qDAAmC;AACnC,oDAAkC;AAClC,qDAAmC;AACnC,kEAAgD;AAChD,gEAA8C;AAC9C,sDAAoC;AACpC,2DAAyC;AAEzC,iDAA+B"}
|
@@ -47,6 +47,7 @@ export declare function useFormValidationSlice(params: {
|
|
47
47
|
registrationEmailAsUsername: boolean;
|
48
48
|
};
|
49
49
|
};
|
50
|
+
/** NOTE: Try to avoid passing a new ref every render for better performances. */
|
50
51
|
passwordValidators?: Validators;
|
51
52
|
}): {
|
52
53
|
formValidationState: {
|
@@ -43,7 +43,6 @@ var react_1 = require("react");
|
|
43
43
|
var useKcMessage_1 = require("./i18n/useKcMessage");
|
44
44
|
var useConstCallback_1 = require("powerhooks/useConstCallback");
|
45
45
|
var id_1 = require("tsafe/id");
|
46
|
-
var useConst_1 = require("powerhooks/useConst");
|
47
46
|
var emailRegExp_1 = require("./tools/emailRegExp");
|
48
47
|
function useGetErrors(params) {
|
49
48
|
var _a = params.kcContext, messagesPerField = _a.messagesPerField, attributes = _a.profile.attributes;
|
@@ -227,7 +226,7 @@ function useFormValidationSlice(params) {
|
|
227
226
|
"min": "4",
|
228
227
|
},
|
229
228
|
} : _a;
|
230
|
-
var attributesWithPassword = (0,
|
229
|
+
var attributesWithPassword = (0, react_1.useMemo)(function () {
|
231
230
|
return !kcContext.passwordRequired
|
232
231
|
? kcContext.profile.attributes
|
233
232
|
: (function () {
|
@@ -263,7 +262,7 @@ function useFormValidationSlice(params) {
|
|
263
262
|
}),
|
264
263
|
])), false); }, []);
|
265
264
|
})();
|
266
|
-
});
|
265
|
+
}, [kcContext, passwordValidators]);
|
267
266
|
var getErrors = useGetErrors({
|
268
267
|
"kcContext": {
|
269
268
|
"messagesPerField": kcContext.messagesPerField,
|
@@ -272,7 +271,7 @@ function useFormValidationSlice(params) {
|
|
272
271
|
},
|
273
272
|
},
|
274
273
|
}).getErrors;
|
275
|
-
var initialInternalState = (0,
|
274
|
+
var initialInternalState = (0, react_1.useMemo)(function () {
|
276
275
|
return Object.fromEntries(attributesWithPassword
|
277
276
|
.map(function (attribute) { return ({
|
278
277
|
attribute: attribute,
|
@@ -296,7 +295,7 @@ function useFormValidationSlice(params) {
|
|
296
295
|
},
|
297
296
|
];
|
298
297
|
}));
|
299
|
-
});
|
298
|
+
}, [attributesWithPassword]);
|
300
299
|
var _b = __read((0, react_1.useReducer)(function (state, params) {
|
301
300
|
var _a;
|
302
301
|
return (__assign(__assign({}, state), (_a = {}, _a[params.name] = __assign(__assign({}, state[params.name]), (function () {
|
@@ -327,7 +326,7 @@ function useFormValidationSlice(params) {
|
|
327
326
|
var _b = __read(_a, 2), name = _b[0], _c = _b[1], value = _c.value, errors = _c.errors;
|
328
327
|
return errors.length === 0 && (value !== "" || !attributesWithPassword.find(function (attribute) { return attribute.name === name; }).required);
|
329
328
|
}),
|
330
|
-
}); }, [formValidationInternalState]);
|
329
|
+
}); }, [formValidationInternalState, attributesWithPassword]);
|
331
330
|
return { formValidationState: formValidationState, formValidationReducer: formValidationReducer, attributesWithPassword: attributesWithPassword };
|
332
331
|
}
|
333
332
|
exports.useFormValidationSlice = useFormValidationSlice;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useFormValidationSlice.js","sourceRoot":"","sources":["../src/lib/useFormValidationSlice.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuC;AACvC,+BAAsD;AAEtD,oDAAmD;AACnD,gEAA+D;AAC/D,+BAA8B;AAE9B,
|
1
|
+
{"version":3,"file":"useFormValidationSlice.js","sourceRoot":"","sources":["../src/lib/useFormValidationSlice.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAAuC;AACvC,+BAAsD;AAEtD,oDAAmD;AACnD,gEAA+D;AAC/D,+BAA8B;AAE9B,mDAAkD;AASlD,SAAgB,YAAY,CAAC,MAO5B;IAEO,IAAA,KAIA,MAAM,UADL,EAFG,gBAAgB,sBAAA,EACL,UAAU,wBACxB,CACM;IAEL,IAAA,KAA+C,IAAA,2BAAY,GAAE,EAA3D,GAAG,SAAA,EAAE,MAAM,YAAA,EAAE,WAAW,iBAAA,EAAE,cAAc,oBAAmB,CAAC;IAEpE,IAAM,SAAS,GAAG,IAAA,mCAAgB,EAAC,UAAC,MAAsF;;QAC9G,IAAA,IAAI,GAAgC,MAAM,KAAtC,EAAE,yBAAyB,GAAK,MAAM,0BAAX,CAAY;QAE3C,IAAA,KAAK,GAAK,yBAAyB,CA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G,CAG/G,CAAC,CACL;QACD,mBAAmB,EAAE,MAAM,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC,KAAK,CAClE,UAAC,EAAyB;gBAAzB,KAAA,aAAyB,EAAxB,IAAI,QAAA,EAAE,UAAiB,EAAf,KAAK,WAAA,EAAE,MAAM,YAAA;YACnB,OAAA,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,UAAA,SAAS,IAAI,OAAA,SAAS,CAAC,IAAI,KAAK,IAAI,EAAvB,CAAuB,CAAE,CAAC,QAAQ,CAAC;QAArH,CAAqH,CAC5H;KACJ,CAAC,EAXI,CAWJ,EACF,CAAC,2BAA2B,EAAE,sBAAsB,CAAC,CACxD,CAAC;IAEF,OAAO,EAAE,mBAAmB,qBAAA,EAAE,qBAAqB,uBAAA,EAAE,sBAAsB,wBAAA,EAAE,CAAC;AAClF,CAAC;AAjKD,wDAiKC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "keycloakify",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.2.2",
|
4
4
|
"description": "Keycloak theme generator for Reacts app",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -315,7 +315,7 @@
|
|
315
315
|
"homepage": "https://github.com/garronej/keycloakify",
|
316
316
|
"peerDependencies": {
|
317
317
|
"@emotion/react": "^11.4.1",
|
318
|
-
"powerhooks": "^0.
|
318
|
+
"powerhooks": "^0.10.0",
|
319
319
|
"react": "^16.8.0 || ^17.0.0",
|
320
320
|
"tss-react": "^1.1.0"
|
321
321
|
},
|
@@ -338,7 +338,7 @@
|
|
338
338
|
"cheerio": "^1.0.0-rc.5",
|
339
339
|
"evt": "2.0.0-beta.38",
|
340
340
|
"minimal-polyfills": "^2.2.1",
|
341
|
-
"path": "^0.
|
341
|
+
"path-browserify": "^1.0.1",
|
342
342
|
"react-markdown": "^5.0.3",
|
343
343
|
"scripting-tools": "^0.19.13",
|
344
344
|
"tsafe": "^0.8.1"
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export type { KcContextBase } from "./KcContextBase";
|
1
|
+
export type { KcContextBase, Attribute, Validators } from "./KcContextBase";
|
2
2
|
export { getKcContext } from "./getKcContext";
|
package/src/lib/index.ts
CHANGED
@@ -5,7 +5,6 @@ import { useKcMessage } from "./i18n/useKcMessage";
|
|
5
5
|
import { useConstCallback } from "powerhooks/useConstCallback";
|
6
6
|
import { id } from "tsafe/id";
|
7
7
|
import type { MessageKey } from "./i18n/useKcMessage";
|
8
|
-
import { useConst } from "powerhooks/useConst";
|
9
8
|
import { emailRegexp } from "./tools/emailRegExp";
|
10
9
|
|
11
10
|
export type KcContextLike = {
|
@@ -278,6 +277,7 @@ export function useFormValidationSlice(params: {
|
|
278
277
|
passwordRequired: boolean;
|
279
278
|
realm: { registrationEmailAsUsername: boolean };
|
280
279
|
};
|
280
|
+
/** NOTE: Try to avoid passing a new ref every render for better performances. */
|
281
281
|
passwordValidators?: Validators;
|
282
282
|
}) {
|
283
283
|
const {
|
@@ -290,49 +290,51 @@ export function useFormValidationSlice(params: {
|
|
290
290
|
},
|
291
291
|
} = params;
|
292
292
|
|
293
|
-
const attributesWithPassword =
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
"
|
322
|
-
"
|
323
|
-
|
324
|
-
|
325
|
-
|
293
|
+
const attributesWithPassword = useMemo(
|
294
|
+
() =>
|
295
|
+
!kcContext.passwordRequired
|
296
|
+
? kcContext.profile.attributes
|
297
|
+
: (() => {
|
298
|
+
const name = kcContext.realm.registrationEmailAsUsername ? "email" : "username";
|
299
|
+
|
300
|
+
return kcContext.profile.attributes.reduce<Attribute[]>(
|
301
|
+
(prev, curr) => [
|
302
|
+
...prev,
|
303
|
+
...(curr.name !== name
|
304
|
+
? [curr]
|
305
|
+
: [
|
306
|
+
curr,
|
307
|
+
id<Attribute>({
|
308
|
+
"name": "password",
|
309
|
+
"displayName": id<`\${${MessageKey}}`>("${password}"),
|
310
|
+
"required": true,
|
311
|
+
"readOnly": false,
|
312
|
+
"validators": passwordValidators,
|
313
|
+
"annotations": {},
|
314
|
+
"groupAnnotations": {},
|
315
|
+
}),
|
316
|
+
id<Attribute>({
|
317
|
+
"name": "password-confirm",
|
318
|
+
"displayName": id<`\${${MessageKey}}`>("${passwordConfirm}"),
|
319
|
+
"required": true,
|
320
|
+
"readOnly": false,
|
321
|
+
"validators": {
|
322
|
+
"_compareToOther": {
|
323
|
+
"name": "password",
|
324
|
+
"ignore.empty.value": true,
|
325
|
+
"shouldBe": "equal",
|
326
|
+
"error-message": id<`\${${MessageKey}}`>("${invalidPasswordConfirmMessage}"),
|
327
|
+
},
|
326
328
|
},
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
)
|
335
|
-
|
329
|
+
"annotations": {},
|
330
|
+
"groupAnnotations": {},
|
331
|
+
}),
|
332
|
+
]),
|
333
|
+
],
|
334
|
+
[],
|
335
|
+
);
|
336
|
+
})(),
|
337
|
+
[kcContext, passwordValidators],
|
336
338
|
);
|
337
339
|
|
338
340
|
const { getErrors } = useGetErrors({
|
@@ -344,27 +346,29 @@ export function useFormValidationSlice(params: {
|
|
344
346
|
},
|
345
347
|
});
|
346
348
|
|
347
|
-
const initialInternalState =
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
attribute
|
352
|
-
|
353
|
-
"
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
attribute
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
349
|
+
const initialInternalState = useMemo(
|
350
|
+
() =>
|
351
|
+
Object.fromEntries(
|
352
|
+
attributesWithPassword
|
353
|
+
.map(attribute => ({
|
354
|
+
attribute,
|
355
|
+
"errors": getErrors({
|
356
|
+
"name": attribute.name,
|
357
|
+
"fieldValueByAttributeName": Object.fromEntries(
|
358
|
+
attributesWithPassword.map(({ name, value }) => [name, { "value": value ?? "" }]),
|
359
|
+
),
|
360
|
+
}),
|
361
|
+
}))
|
362
|
+
.map(({ attribute, errors }) => [
|
363
|
+
attribute.name,
|
364
|
+
{
|
365
|
+
"value": attribute.value ?? "",
|
366
|
+
errors,
|
367
|
+
"doDisplayPotentialErrorMessages": errors.length !== 0,
|
368
|
+
},
|
369
|
+
]),
|
370
|
+
),
|
371
|
+
[attributesWithPassword],
|
368
372
|
);
|
369
373
|
|
370
374
|
type InternalState = typeof initialInternalState;
|
@@ -421,7 +425,7 @@ export function useFormValidationSlice(params: {
|
|
421
425
|
errors.length === 0 && (value !== "" || !attributesWithPassword.find(attribute => attribute.name === name)!.required),
|
422
426
|
),
|
423
427
|
}),
|
424
|
-
[formValidationInternalState],
|
428
|
+
[formValidationInternalState, attributesWithPassword],
|
425
429
|
);
|
426
430
|
|
427
431
|
return { formValidationState, formValidationReducer, attributesWithPassword };
|