@jsb188/auth-web 1.1.10 → 1.1.11
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/package.json +25 -25
- package/src/hooks/use-oauth.tsx +341 -311
- package/src/modules/AssignRequiredAuth.tsx +182 -170
- package/src/modules/AuthFormUI.tsx +28 -28
- package/src/modules/AuthForms-SSO.tsx +188 -151
- package/src/modules/AuthForms.tsx +676 -607
- package/src/modules/AuthGate.tsx +108 -85
- package/src/modules/InlineAuthForm.tsx +129 -116
- package/src/modules/ManagedSessions.tsx +109 -83
- package/src/modules/OtherAuthButtons.tsx +73 -71
- package/src/modules/_helpers.ts +102 -84
- package/src/modules/schemas.ts +231 -202
- package/src/schemas/account.ts +153 -138
- package/src/schemas/address.ts +155 -138
- package/src/ui/ManagedSessionUI.tsx +70 -64
package/src/modules/schemas.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
isPhone,
|
|
4
|
+
isEmail,
|
|
5
|
+
passwordStrength,
|
|
6
|
+
} from '@jsb188/app/utils/string.ts';
|
|
3
7
|
|
|
4
8
|
/**
|
|
5
9
|
* Types
|
|
6
10
|
*/
|
|
7
11
|
|
|
8
12
|
interface SignInFormType {
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
identifier?: string;
|
|
14
|
+
password?: string;
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
interface SignUpFormType {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
email: string;
|
|
19
|
+
password: string;
|
|
20
|
+
passwordRepeat: string;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
interface SignInDataForSchema {
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
hidePassword: boolean;
|
|
25
|
+
lastIdentifier: string;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/**
|
|
@@ -26,106 +30,122 @@ interface SignInDataForSchema {
|
|
|
26
30
|
*/
|
|
27
31
|
|
|
28
32
|
const MIN_LEN_VALUES = {
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
password: 8,
|
|
34
|
+
description: 750,
|
|
31
35
|
};
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
38
|
* Rules for each field
|
|
35
39
|
*/
|
|
36
40
|
|
|
37
|
-
const RULES = function() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
41
|
+
const RULES = (function () {
|
|
42
|
+
return {
|
|
43
|
+
email: {
|
|
44
|
+
for: 'email',
|
|
45
|
+
rule: isEmail,
|
|
46
|
+
error: (value: string) => ({
|
|
47
|
+
message: i18n.t('error.msg_email_invalid', { value }),
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
50
|
+
password: {
|
|
51
|
+
for: 'password',
|
|
52
|
+
rule: (value: string) =>
|
|
53
|
+
passwordStrength(value, MIN_LEN_VALUES.password).valid,
|
|
54
|
+
error: (value: string) => {
|
|
55
|
+
const {
|
|
56
|
+
isLongEnough,
|
|
57
|
+
hasLowercase,
|
|
58
|
+
hasUppercase,
|
|
59
|
+
hasDigit,
|
|
60
|
+
hasSpecial,
|
|
61
|
+
} = passwordStrength(value, MIN_LEN_VALUES.password);
|
|
62
|
+
const errorMessages = [];
|
|
52
63
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (!isLongEnough) {
|
|
65
|
+
errorMessages.push(
|
|
66
|
+
i18n.t('error.msg_password_too_short', {
|
|
67
|
+
length: MIN_LEN_VALUES.password,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
if (!hasLowercase) {
|
|
72
|
+
errorMessages.push(i18n.t('error.msg_password_lowercase'));
|
|
73
|
+
}
|
|
74
|
+
if (!hasUppercase) {
|
|
75
|
+
errorMessages.push(i18n.t('error.msg_password_uppercase'));
|
|
76
|
+
}
|
|
77
|
+
if (!hasDigit) {
|
|
78
|
+
errorMessages.push(i18n.t('error.msg_password_digit'));
|
|
79
|
+
}
|
|
80
|
+
if (!hasSpecial) {
|
|
81
|
+
errorMessages.push(i18n.t('error.msg_password_special'));
|
|
82
|
+
}
|
|
70
83
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
84
|
+
return {
|
|
85
|
+
message:
|
|
86
|
+
errorMessages.length > 1
|
|
87
|
+
? i18n.t('error.msg_password_insecure')
|
|
88
|
+
: errorMessages[0],
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
passwordRepeat: {
|
|
93
|
+
for: 'passwordRepeat',
|
|
94
|
+
rule: (value: string, formValues: Partial<SignUpFormType>) =>
|
|
95
|
+
value === formValues.password,
|
|
96
|
+
error: {
|
|
97
|
+
message: i18n.t('error.msg_password_mismatch'),
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
phone: {
|
|
101
|
+
for: 'phone',
|
|
102
|
+
rule: (value: string) => isPhone(value),
|
|
103
|
+
error: (value: string) => ({
|
|
104
|
+
message: i18n.t('error.msg_phone_invalid', { value }),
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
})();
|
|
92
109
|
|
|
93
110
|
/**
|
|
94
111
|
* Schema; Change password
|
|
95
112
|
*/
|
|
96
113
|
|
|
97
114
|
export const makeChangeAccountPasswordSchema = () => ({
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
listData: [
|
|
116
|
+
{
|
|
117
|
+
__type: 'input',
|
|
118
|
+
hidden: (dataForSchema?: SignInDataForSchema) =>
|
|
119
|
+
!!dataForSchema?.hidePassword,
|
|
120
|
+
item: {
|
|
121
|
+
autoFocus: true,
|
|
122
|
+
name: 'currentPassword',
|
|
123
|
+
type: 'password',
|
|
124
|
+
label: i18n.t('account.currentPassword'),
|
|
125
|
+
placeholder: i18n.t('account.password_ph'),
|
|
126
|
+
// info: 'whatever you want',
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
__type: 'password',
|
|
131
|
+
item: {
|
|
132
|
+
name: 'password',
|
|
133
|
+
type: 'password',
|
|
134
|
+
label: i18n.t('account.newPassword'),
|
|
135
|
+
// placeholder: ''
|
|
136
|
+
// info: 'whatever you want',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
__type: 'password',
|
|
141
|
+
item: {
|
|
142
|
+
name: 'passwordRepeat',
|
|
143
|
+
type: 'password',
|
|
144
|
+
label: i18n.t('account.newPasswordRepeat'),
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
rules: [RULES.password],
|
|
129
149
|
});
|
|
130
150
|
|
|
131
151
|
/**
|
|
@@ -133,27 +153,28 @@ export const makeChangeAccountPasswordSchema = () => ({
|
|
|
133
153
|
*/
|
|
134
154
|
|
|
135
155
|
export const makeAssignPasswordSchema = () => ({
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
listData: [
|
|
157
|
+
{
|
|
158
|
+
__type: 'password',
|
|
159
|
+
item: {
|
|
160
|
+
name: 'password',
|
|
161
|
+
type: 'password',
|
|
162
|
+
label: i18n.t('account.password'),
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
__type: 'password',
|
|
167
|
+
item: {
|
|
168
|
+
name: 'passwordRepeat',
|
|
169
|
+
type: 'password',
|
|
170
|
+
label: i18n.t('account.passwordRepeat'),
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
rules: [RULES.password],
|
|
175
|
+
isButtonDisabled: (formValues: any) => {
|
|
176
|
+
return !formValues?.password?.trim() || !formValues?.passwordRepeat?.trim();
|
|
177
|
+
},
|
|
157
178
|
});
|
|
158
179
|
|
|
159
180
|
/**
|
|
@@ -161,30 +182,34 @@ export const makeAssignPasswordSchema = () => ({
|
|
|
161
182
|
*/
|
|
162
183
|
|
|
163
184
|
export const makeSignInSchema = () => ({
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
185
|
+
listData: [
|
|
186
|
+
{
|
|
187
|
+
__type: 'input',
|
|
188
|
+
// Can't do this because disabling the input will make post form ignore this field
|
|
189
|
+
// locked: ({ hidePassword, lastIdentifier }: SignInDataForSchema) => !hidePassword && !!lastIdentifier,
|
|
190
|
+
item: {
|
|
191
|
+
name: 'identifier',
|
|
192
|
+
allowClearIfLocked: true,
|
|
193
|
+
label: i18n.t('auth.login_opts_main'),
|
|
194
|
+
placeholder: i18n.t('account.email_ph'),
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
__type: 'password',
|
|
199
|
+
hidden: (dataForSchema?: SignInDataForSchema) =>
|
|
200
|
+
!!dataForSchema?.hidePassword,
|
|
201
|
+
autoFocus: true,
|
|
202
|
+
item: {
|
|
203
|
+
name: 'password',
|
|
204
|
+
type: 'password',
|
|
205
|
+
label: i18n.t('account.password'),
|
|
206
|
+
placeholder: i18n.t('account.password_ph'),
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
isButtonDisabled: (formValues: SignInFormType) => {
|
|
211
|
+
return !formValues?.identifier?.trim();
|
|
212
|
+
},
|
|
188
213
|
});
|
|
189
214
|
|
|
190
215
|
/**
|
|
@@ -192,39 +217,43 @@ export const makeSignInSchema = () => ({
|
|
|
192
217
|
*/
|
|
193
218
|
|
|
194
219
|
export const makeSignUpSchema = () => ({
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
220
|
+
listData: [
|
|
221
|
+
{
|
|
222
|
+
__type: 'input',
|
|
223
|
+
item: {
|
|
224
|
+
name: 'email',
|
|
225
|
+
label: i18n.t('account.email'),
|
|
226
|
+
placeholder: i18n.t('account.email_ph'),
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
__type: 'password',
|
|
231
|
+
item: {
|
|
232
|
+
name: 'password',
|
|
233
|
+
type: 'password',
|
|
234
|
+
label: i18n.t('account.password'),
|
|
235
|
+
placeholder: i18n.t('account.password_ph'),
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
__type: 'password',
|
|
240
|
+
item: {
|
|
241
|
+
name: 'passwordRepeat',
|
|
242
|
+
type: 'password',
|
|
243
|
+
label: i18n.t('account.passwordRepeat'),
|
|
244
|
+
placeholder: i18n.t('account.password_ph'),
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
isButtonDisabled: (formValues: Partial<SignUpFormType>) => {
|
|
249
|
+
const fields: (keyof SignUpFormType)[] = [
|
|
250
|
+
'email',
|
|
251
|
+
'password',
|
|
252
|
+
'passwordRepeat',
|
|
253
|
+
];
|
|
254
|
+
return fields.some((s) => !formValues[s]?.trim());
|
|
255
|
+
},
|
|
256
|
+
rules: [RULES.email, RULES.password, RULES.passwordRepeat],
|
|
228
257
|
});
|
|
229
258
|
|
|
230
259
|
/**
|
|
@@ -232,24 +261,24 @@ export const makeSignUpSchema = () => ({
|
|
|
232
261
|
*/
|
|
233
262
|
|
|
234
263
|
interface RequestTokenizedEmailObj {
|
|
235
|
-
|
|
264
|
+
email: string;
|
|
236
265
|
}
|
|
237
266
|
|
|
238
267
|
export const makeRequestTokenizedEmailSchema = () => ({
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
268
|
+
listData: [
|
|
269
|
+
{
|
|
270
|
+
__type: 'input',
|
|
271
|
+
item: {
|
|
272
|
+
name: 'email',
|
|
273
|
+
label: i18n.t('account.email'),
|
|
274
|
+
placeholder: i18n.t('account.email_ph'),
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
isButtonDisabled: (formValues: Partial<RequestTokenizedEmailObj>) => {
|
|
279
|
+
return !formValues.email?.trim();
|
|
280
|
+
},
|
|
281
|
+
rules: [RULES.email],
|
|
253
282
|
});
|
|
254
283
|
|
|
255
284
|
/**
|
|
@@ -257,22 +286,22 @@ export const makeRequestTokenizedEmailSchema = () => ({
|
|
|
257
286
|
*/
|
|
258
287
|
|
|
259
288
|
interface SendPhoneVerificationObj {
|
|
260
|
-
|
|
289
|
+
phone: string;
|
|
261
290
|
}
|
|
262
291
|
|
|
263
292
|
export const makeSendPhoneVerificationSchema = () => ({
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
293
|
+
listData: [
|
|
294
|
+
{
|
|
295
|
+
__type: 'input',
|
|
296
|
+
item: {
|
|
297
|
+
name: 'phone',
|
|
298
|
+
label: i18n.t('form.phone_number'),
|
|
299
|
+
placeholder: i18n.t('account.phone_ph'),
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
isButtonDisabled: (formValues: Partial<SendPhoneVerificationObj>) => {
|
|
304
|
+
return !formValues.phone?.trim();
|
|
305
|
+
},
|
|
306
|
+
rules: [RULES.phone],
|
|
278
307
|
});
|