@jsb188/auth-web 1.1.3 → 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 -18
- package/src/hooks/use-oauth.tsx +375 -142
- package/src/main.ts +8 -1
- package/src/modules/AssignRequiredAuth.tsx +240 -0
- package/src/modules/AuthFormUI.tsx +45 -0
- package/src/modules/AuthForms-SSO.tsx +224 -0
- package/src/modules/AuthForms.tsx +781 -0
- package/src/modules/AuthGate.tsx +120 -53
- package/src/modules/InlineAuthForm.tsx +161 -0
- package/src/modules/ManagedSessions.tsx +135 -0
- package/src/modules/OtherAuthButtons.tsx +116 -0
- package/src/modules/_helpers.ts +143 -0
- package/src/modules/schemas.ts +248 -203
- package/src/schemas/account.ts +177 -0
- package/src/schemas/address.ts +182 -0
- package/src/schemas/index.ts +2 -0
- package/src/ui/ManagedSessionUI.tsx +95 -0
- package/src/modules/AuthForm.tsx +0 -638
- package/src/modules/ContinueWithApple.tsx +0 -105
- package/src/modules/OAuthButtons.tsx +0 -48
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { SUPPORTED_LANGUAGES } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
import type { AccountData } from '@jsb188/app/types/auth.d.ts';
|
|
4
|
+
import { formatPhoneNumber } from '@jsb188/app/utils/string.ts';
|
|
5
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Length values for validation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const MIN_LEN_VALUES = {
|
|
12
|
+
password: 8,
|
|
13
|
+
firstName: 32,
|
|
14
|
+
lastName: 32,
|
|
15
|
+
description: 750,
|
|
16
|
+
email: 80,
|
|
17
|
+
phone: 15,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Schema; Edit account
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export function makeEditAccountSchema(
|
|
25
|
+
formId: string,
|
|
26
|
+
focusedName: string,
|
|
27
|
+
formValues: any,
|
|
28
|
+
account: AccountData | null,
|
|
29
|
+
openModalPopUp: OpenModalPopUpFn,
|
|
30
|
+
) {
|
|
31
|
+
const poProps = {
|
|
32
|
+
// scrollAreaDOMId,
|
|
33
|
+
zClassName: 'z9',
|
|
34
|
+
position: 'bottom_left',
|
|
35
|
+
offsetX: 0,
|
|
36
|
+
offsetY: 7,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
listData: [
|
|
41
|
+
{
|
|
42
|
+
// __type: 'subtitle',
|
|
43
|
+
// item: {
|
|
44
|
+
// text: i18n.t('account.profile'),
|
|
45
|
+
// },
|
|
46
|
+
// }, {
|
|
47
|
+
__type: 'group',
|
|
48
|
+
item: {
|
|
49
|
+
items: [
|
|
50
|
+
{
|
|
51
|
+
__type: 'input',
|
|
52
|
+
item: {
|
|
53
|
+
name: 'profile.firstName',
|
|
54
|
+
maxLength: MIN_LEN_VALUES.firstName,
|
|
55
|
+
label: i18n.t('account.fName'),
|
|
56
|
+
placeholder: account?.profile?.firstName,
|
|
57
|
+
autoComplete: 'off',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
__type: 'input',
|
|
62
|
+
item: {
|
|
63
|
+
name: 'profile.lastName',
|
|
64
|
+
maxLength: MIN_LEN_VALUES.lastName,
|
|
65
|
+
label: i18n.t('account.lName'),
|
|
66
|
+
placeholder: account?.profile?.lastName,
|
|
67
|
+
autoComplete: 'off',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
__type: 'input_click',
|
|
75
|
+
forceClickId: 'input_click_settings.language',
|
|
76
|
+
label: i18n.t('form.activity'),
|
|
77
|
+
item: {
|
|
78
|
+
label: i18n.t('account.ai_language'),
|
|
79
|
+
locked: true,
|
|
80
|
+
focused: focusedName === formId + '_settings.language',
|
|
81
|
+
name: 'settings.language',
|
|
82
|
+
placeholder: i18n.t(`form.activity_ph`),
|
|
83
|
+
getter: (value: string) => i18n.t(`form.lang.${value || 'en'}`),
|
|
84
|
+
|
|
85
|
+
popOverProps: {
|
|
86
|
+
id: formId + '_settings.language',
|
|
87
|
+
...poProps,
|
|
88
|
+
iface: {
|
|
89
|
+
name: 'PO_LIST',
|
|
90
|
+
variables: {
|
|
91
|
+
designClassName: 'w_400',
|
|
92
|
+
className: 'max_h_40vh',
|
|
93
|
+
options: SUPPORTED_LANGUAGES.map((lang) => ({
|
|
94
|
+
__type: 'LIST_ITEM' as const,
|
|
95
|
+
text: i18n.t(`form.lang.${lang}`),
|
|
96
|
+
// textClassName: 'ft_xs',
|
|
97
|
+
// rightIconClassName: 'ft_xs mb_2',
|
|
98
|
+
name: 'settings.language',
|
|
99
|
+
value: lang,
|
|
100
|
+
selected: (formValues?.settings?.language || 'en') === lang,
|
|
101
|
+
})),
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
__type: 'input_w_button',
|
|
109
|
+
item: {
|
|
110
|
+
name: 'change_phoneNumber',
|
|
111
|
+
maxLength: MIN_LEN_VALUES.phone,
|
|
112
|
+
setter: (data: any) =>
|
|
113
|
+
formatPhoneNumber(
|
|
114
|
+
data?.change_phoneNumber || data?.phone?.number || '',
|
|
115
|
+
),
|
|
116
|
+
label: i18n.t('form.phone_number'),
|
|
117
|
+
autoComplete: 'off',
|
|
118
|
+
disabled: true,
|
|
119
|
+
buttonText: i18n.t('form.change'),
|
|
120
|
+
onClickButton: () =>
|
|
121
|
+
openModalPopUp({
|
|
122
|
+
preset: 'CHANGE_PHONE',
|
|
123
|
+
name: 'edit_account_phone',
|
|
124
|
+
}),
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
__type: 'input_w_button',
|
|
129
|
+
item: {
|
|
130
|
+
name: 'change_emailAddress',
|
|
131
|
+
maxLength: MIN_LEN_VALUES.email,
|
|
132
|
+
setter: (data: any) =>
|
|
133
|
+
data?.change_emailAddress || data?.email?.address,
|
|
134
|
+
label: i18n.t('account.email'),
|
|
135
|
+
autoComplete: 'off',
|
|
136
|
+
disabled: true,
|
|
137
|
+
buttonText: i18n.t('form.change'),
|
|
138
|
+
onClickButton: () =>
|
|
139
|
+
openModalPopUp({
|
|
140
|
+
preset: 'CHANGE_EMAIL',
|
|
141
|
+
name: 'edit_account_email',
|
|
142
|
+
}),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
__type: 'input_w_button',
|
|
147
|
+
item: {
|
|
148
|
+
name: 'change_password',
|
|
149
|
+
minLength: MIN_LEN_VALUES.password,
|
|
150
|
+
label: i18n.t('account.password'),
|
|
151
|
+
setter: () => '....',
|
|
152
|
+
autoComplete: 'off',
|
|
153
|
+
type: 'password',
|
|
154
|
+
disabled: true,
|
|
155
|
+
buttonText: i18n.t('form.change'),
|
|
156
|
+
onClickButton: () =>
|
|
157
|
+
openModalPopUp({
|
|
158
|
+
preset: 'CHANGE_PASSWORD',
|
|
159
|
+
name: 'edit_account_password',
|
|
160
|
+
}),
|
|
161
|
+
},
|
|
162
|
+
// __type: 'textarea',
|
|
163
|
+
// item: {
|
|
164
|
+
// name: 'description',
|
|
165
|
+
// maxLength: MIN_LEN_VALUES.description,
|
|
166
|
+
// setter: (data: any) => data?.profile?.description,
|
|
167
|
+
// label: i18n.t('account.about'),
|
|
168
|
+
// placeholder: i18n.t('account.about_ph'),
|
|
169
|
+
// autoComplete: 'off',
|
|
170
|
+
// },
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
rules: [
|
|
174
|
+
// RULES.password,
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { SUPPORTED_COUNTRIES } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import i18n from '@jsb188/app/i18n/index.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Length values for address field validation.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const MIN_LEN_VALUES = {
|
|
9
|
+
city: 100,
|
|
10
|
+
state: 32,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Build a required-address-field validator.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
function makeAddressRequiredRule(fieldName: string, labelKey: string) {
|
|
18
|
+
return {
|
|
19
|
+
for: `address.${fieldName}`,
|
|
20
|
+
rule: (_value: unknown, formValues: any) => {
|
|
21
|
+
const address = formValues?.address || {};
|
|
22
|
+
const hasAddressValueExceptCountry = [
|
|
23
|
+
'line1',
|
|
24
|
+
'line2',
|
|
25
|
+
'city',
|
|
26
|
+
'state',
|
|
27
|
+
'postalCode',
|
|
28
|
+
].some((key) => {
|
|
29
|
+
return String(address?.[key] || '').trim().length > 0;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (!hasAddressValueExceptCountry) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return String(address?.[fieldName] || '').trim().length > 0;
|
|
37
|
+
},
|
|
38
|
+
error: () => ({
|
|
39
|
+
message: i18n.t('error.msg_value_required', { value: i18n.t(labelKey) }),
|
|
40
|
+
}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create reusable address schema section and rules.
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
export function makeAddressSchema(
|
|
49
|
+
formId: string,
|
|
50
|
+
focusedName: string,
|
|
51
|
+
addressFormValues?: Partial<{
|
|
52
|
+
line1: string | null;
|
|
53
|
+
line2: string | null;
|
|
54
|
+
city: string | null;
|
|
55
|
+
state: string | null;
|
|
56
|
+
postalCode: string | null;
|
|
57
|
+
country: string | null;
|
|
58
|
+
}> | null,
|
|
59
|
+
popOverDesignClassName?: string,
|
|
60
|
+
) {
|
|
61
|
+
const currentAddress = addressFormValues || {};
|
|
62
|
+
const selectedCountryCode = currentAddress?.country || '';
|
|
63
|
+
const priorityCountryOptions = ['US', 'MX', 'CA'].map((countryCode) => ({
|
|
64
|
+
__type: 'LIST_ITEM' as const,
|
|
65
|
+
text: i18n.t(`country.from_code.${countryCode}`),
|
|
66
|
+
name: 'address.country',
|
|
67
|
+
value: countryCode,
|
|
68
|
+
selected: selectedCountryCode === countryCode,
|
|
69
|
+
}));
|
|
70
|
+
const supportedCountryOptions = SUPPORTED_COUNTRIES.map((countryCode) => ({
|
|
71
|
+
__type: 'LIST_ITEM' as const,
|
|
72
|
+
text: i18n.t(`country.from_code.${countryCode}`),
|
|
73
|
+
name: 'address.country',
|
|
74
|
+
value: countryCode,
|
|
75
|
+
selected: selectedCountryCode === countryCode,
|
|
76
|
+
}));
|
|
77
|
+
const countryOptions = [
|
|
78
|
+
...priorityCountryOptions,
|
|
79
|
+
{
|
|
80
|
+
__type: 'BREAK' as const,
|
|
81
|
+
},
|
|
82
|
+
...supportedCountryOptions,
|
|
83
|
+
];
|
|
84
|
+
const popOverProps = {
|
|
85
|
+
zClassName: 'z9',
|
|
86
|
+
position: 'bottom_left' as const,
|
|
87
|
+
offsetX: 0,
|
|
88
|
+
offsetY: 7,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
listData: [
|
|
93
|
+
{
|
|
94
|
+
__type: 'input' as const,
|
|
95
|
+
item: {
|
|
96
|
+
name: 'address.line1',
|
|
97
|
+
label: i18n.t('form.line1'),
|
|
98
|
+
placeholder: i18n.t('form.line1_ph'),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
__type: 'input' as const,
|
|
103
|
+
item: {
|
|
104
|
+
name: 'address.line2',
|
|
105
|
+
label: i18n.t('form.line2_optional'),
|
|
106
|
+
placeholder: i18n.t('form.line2_ph'),
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
__type: 'input' as const,
|
|
111
|
+
item: {
|
|
112
|
+
name: 'address.postalCode',
|
|
113
|
+
label: i18n.t('form.postalCode'),
|
|
114
|
+
placeholder:
|
|
115
|
+
currentAddress?.postalCode || i18n.t('form.postalCode_ph'),
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
__type: 'group' as const,
|
|
120
|
+
item: {
|
|
121
|
+
items: [
|
|
122
|
+
{
|
|
123
|
+
__type: 'input' as const,
|
|
124
|
+
item: {
|
|
125
|
+
name: 'address.city',
|
|
126
|
+
maxLength: MIN_LEN_VALUES.city,
|
|
127
|
+
label: i18n.t('form.city'),
|
|
128
|
+
placeholder: currentAddress?.city || i18n.t('form.city_ph'),
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
__type: 'input' as const,
|
|
133
|
+
item: {
|
|
134
|
+
name: 'address.state',
|
|
135
|
+
maxLength: MIN_LEN_VALUES.state,
|
|
136
|
+
label: i18n.t('form.state'),
|
|
137
|
+
placeholder: currentAddress?.state || '',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
__type: 'input_click' as const,
|
|
145
|
+
forceClickId: 'input_click_address.country',
|
|
146
|
+
label: i18n.t('form.country'),
|
|
147
|
+
item: {
|
|
148
|
+
label: i18n.t('form.country'),
|
|
149
|
+
locked: true,
|
|
150
|
+
focused: focusedName === formId + '_address.country',
|
|
151
|
+
name: 'address.country',
|
|
152
|
+
getter: (value: string) =>
|
|
153
|
+
value ? i18n.t(`country.from_code.${value}`) : '',
|
|
154
|
+
placeholder: selectedCountryCode || i18n.t('form.country_ph'),
|
|
155
|
+
popOverProps: {
|
|
156
|
+
...popOverProps,
|
|
157
|
+
id: formId + '_address.country',
|
|
158
|
+
doNotFixToBottom: true,
|
|
159
|
+
iface: {
|
|
160
|
+
name: 'PO_LIST',
|
|
161
|
+
variables: {
|
|
162
|
+
designClassName: popOverDesignClassName ?? 'w_400',
|
|
163
|
+
className: 'max_h_50vh',
|
|
164
|
+
initialState: {
|
|
165
|
+
'address.country': selectedCountryCode,
|
|
166
|
+
},
|
|
167
|
+
options: countryOptions,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
rules: [
|
|
175
|
+
makeAddressRequiredRule('line1', 'form.line1'),
|
|
176
|
+
makeAddressRequiredRule('postalCode', 'form.postalCode'),
|
|
177
|
+
makeAddressRequiredRule('city', 'form.city'),
|
|
178
|
+
makeAddressRequiredRule('state', 'form.state'),
|
|
179
|
+
makeAddressRequiredRule('country', 'form.country'),
|
|
180
|
+
],
|
|
181
|
+
};
|
|
182
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { AccountSessionData } from '@jsb188/app/types/auth.d.ts';
|
|
2
|
+
import { cn } from '@jsb188/app/utils/string.ts';
|
|
3
|
+
import { Button } from '@jsb188/react-web/ui/Button';
|
|
4
|
+
import { memo } from 'react';
|
|
5
|
+
|
|
6
|
+
export type ManagedSessionListItem = AccountSessionData & {
|
|
7
|
+
displayExpiresAt: string;
|
|
8
|
+
displayLastActivityAt: string;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* Render one managed login session without owning data or interaction state.
|
|
14
|
+
*/
|
|
15
|
+
const ManagedSessionRowUI = memo(
|
|
16
|
+
(p: {
|
|
17
|
+
item: ManagedSessionListItem;
|
|
18
|
+
revokeText: string;
|
|
19
|
+
currentText: string;
|
|
20
|
+
expiresText: string;
|
|
21
|
+
lastActiveText: string;
|
|
22
|
+
saving: boolean;
|
|
23
|
+
onRevoke: (sessionId: string) => void;
|
|
24
|
+
}) => {
|
|
25
|
+
const { item } = p;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="h_spread gap_df py_12 bd_b_1 bd_lt">
|
|
29
|
+
<div className="min_w_0">
|
|
30
|
+
<div className="h_item gap_8">
|
|
31
|
+
<strong className="ft_medium ellipsis">{item.displayName}</strong>
|
|
32
|
+
{!item.current ? null : (
|
|
33
|
+
<span className="ft_xs cl_active">{p.currentText}</span>
|
|
34
|
+
)}
|
|
35
|
+
</div>
|
|
36
|
+
<p className="ft_sm cl_lt ellipsis">
|
|
37
|
+
{p.lastActiveText.replace('%{date}', item.displayLastActivityAt)}
|
|
38
|
+
</p>
|
|
39
|
+
<p className="ft_xs cl_lt ellipsis">
|
|
40
|
+
{p.expiresText.replace('%{date}', item.displayExpiresAt)}
|
|
41
|
+
</p>
|
|
42
|
+
</div>
|
|
43
|
+
<Button
|
|
44
|
+
size="sm"
|
|
45
|
+
preset={item.current ? 'cl_err' : 'outline'}
|
|
46
|
+
className={cn('shrink_0', p.saving && 'disabled')}
|
|
47
|
+
disabled={p.saving}
|
|
48
|
+
text={p.revokeText}
|
|
49
|
+
onClick={() => p.onRevoke(item.id)}
|
|
50
|
+
/>
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
ManagedSessionRowUI.displayName = 'ManagedSessionRowUI';
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Render a presentation-only list of managed login sessions.
|
|
60
|
+
*/
|
|
61
|
+
export const ManagedSessionListUI = memo(
|
|
62
|
+
(p: {
|
|
63
|
+
items: ManagedSessionListItem[];
|
|
64
|
+
emptyText: string;
|
|
65
|
+
revokeText: string;
|
|
66
|
+
currentText: string;
|
|
67
|
+
expiresText: string;
|
|
68
|
+
lastActiveText: string;
|
|
69
|
+
savingSessionId?: string | null;
|
|
70
|
+
onRevoke: (sessionId: string) => void;
|
|
71
|
+
}) => {
|
|
72
|
+
if (!p.items.length) {
|
|
73
|
+
return <p className="cl_lt py_md">{p.emptyText}</p>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div>
|
|
78
|
+
{p.items.map((item) => (
|
|
79
|
+
<ManagedSessionRowUI
|
|
80
|
+
key={item.id}
|
|
81
|
+
item={item}
|
|
82
|
+
revokeText={p.revokeText}
|
|
83
|
+
currentText={p.currentText}
|
|
84
|
+
expiresText={p.expiresText}
|
|
85
|
+
lastActiveText={p.lastActiveText}
|
|
86
|
+
saving={p.savingSessionId === item.id}
|
|
87
|
+
onRevoke={p.onRevoke}
|
|
88
|
+
/>
|
|
89
|
+
))}
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
},
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
ManagedSessionListUI.displayName = 'ManagedSessionListUI';
|