@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
|
@@ -6,26 +6,32 @@ import SchemaForm from '@jsb188/react-web/modules/SchemaForm';
|
|
|
6
6
|
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
7
7
|
import { FullWidthButton } from '@jsb188/react-web/ui/Button';
|
|
8
8
|
import Markdown from '@jsb188/react-web/ui/Markdown';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
ModalErrorMessage,
|
|
11
|
+
ModalSimpleContent,
|
|
12
|
+
} from '@jsb188/react-web/ui/ModalUI';
|
|
10
13
|
import { AppContext } from '@jsb188/react/states';
|
|
11
14
|
import { useContext, useMemo, useState } from 'react';
|
|
12
15
|
import { AuthFormContainer } from './AuthFormUI';
|
|
13
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
makeAssignPasswordSchema,
|
|
18
|
+
makeRequestTokenizedEmailSchema,
|
|
19
|
+
} from './schemas';
|
|
14
20
|
|
|
15
21
|
/**
|
|
16
22
|
* Types
|
|
17
23
|
*/
|
|
18
24
|
|
|
19
25
|
interface FinishedResultObj {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
26
|
+
hasPassword: boolean;
|
|
27
|
+
email: any;
|
|
28
|
+
}
|
|
23
29
|
|
|
24
30
|
interface RequiredAuthSwitchCaseProps {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
identifier: string;
|
|
32
|
+
onFinish: () => void;
|
|
33
|
+
finishedResult: FinishedResultObj;
|
|
34
|
+
setFinishedResult: any;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
/**
|
|
@@ -33,25 +39,25 @@ interface RequiredAuthSwitchCaseProps {
|
|
|
33
39
|
*/
|
|
34
40
|
|
|
35
41
|
function AccountSecuredMessage(p: RequiredAuthSwitchCaseProps) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
42
|
+
const { onFinish } = p;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<ModalSimpleContent
|
|
46
|
+
// title='Finished!'
|
|
47
|
+
iconName={COMMON_ICON_NAMES.verified}
|
|
48
|
+
className="px_df pt_md"
|
|
49
|
+
>
|
|
50
|
+
<Markdown as="p">{i18n.t('auth.required_auth_fin_msg')}</Markdown>
|
|
51
|
+
|
|
52
|
+
<FullWidthButton
|
|
53
|
+
preset="bg_primary"
|
|
54
|
+
className="mt_md shadow"
|
|
55
|
+
onClick={onFinish}
|
|
56
|
+
>
|
|
57
|
+
{i18n.t('auth.continue_to_app')}
|
|
58
|
+
</FullWidthButton>
|
|
59
|
+
</ModalSimpleContent>
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
63
|
/**
|
|
@@ -59,53 +65,52 @@ function AccountSecuredMessage(p: RequiredAuthSwitchCaseProps) {
|
|
|
59
65
|
*/
|
|
60
66
|
|
|
61
67
|
function SetPasswordForm(p: RequiredAuthSwitchCaseProps) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
</>;
|
|
68
|
+
const { identifier, setFinishedResult } = p;
|
|
69
|
+
const assignPasswordSchema = useMemo(makeAssignPasswordSchema, []);
|
|
70
|
+
|
|
71
|
+
const { changeAccountPassword, saving, error, setError, resetErrors } =
|
|
72
|
+
useChangeAccountPassword({
|
|
73
|
+
doNotFinishForm: true,
|
|
74
|
+
onCompleted: (passwordChanged: boolean) => {
|
|
75
|
+
if (passwordChanged) {
|
|
76
|
+
setFinishedResult((fr: FinishedResultObj) => ({
|
|
77
|
+
...fr,
|
|
78
|
+
hasPassword: true,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const onSubmit = (fv: any) => {
|
|
85
|
+
changeAccountPassword({
|
|
86
|
+
variables: {
|
|
87
|
+
currentPassword: '',
|
|
88
|
+
password: fv.password,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<>
|
|
95
|
+
<p className="a_c mx_df mb_df -mt_5 pb_xs">
|
|
96
|
+
{i18n.t('auth.add_password_sign_in_msg', { identifier })}
|
|
97
|
+
</p>
|
|
98
|
+
|
|
99
|
+
<SchemaForm
|
|
100
|
+
className="pb_df fs"
|
|
101
|
+
saving={saving}
|
|
102
|
+
schema={assignPasswordSchema}
|
|
103
|
+
// currentData={{}}
|
|
104
|
+
onError={setError}
|
|
105
|
+
onSubmit={onSubmit}
|
|
106
|
+
buttonText={i18n.t('auth.add_password')}
|
|
107
|
+
>
|
|
108
|
+
{!error ? null : (
|
|
109
|
+
<ModalErrorMessage error={error} resetErrors={resetErrors} />
|
|
110
|
+
)}
|
|
111
|
+
</SchemaForm>
|
|
112
|
+
</>
|
|
113
|
+
);
|
|
109
114
|
}
|
|
110
115
|
|
|
111
116
|
/**
|
|
@@ -113,58 +118,59 @@ function SetPasswordForm(p: RequiredAuthSwitchCaseProps) {
|
|
|
113
118
|
*/
|
|
114
119
|
|
|
115
120
|
function SetEmailForm(p: RequiredAuthSwitchCaseProps) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
121
|
+
const { identifier } = p;
|
|
122
|
+
const [waitingForVerification, setWaitingForVerification] = useState(false);
|
|
123
|
+
const assignPasswordSchema = useMemo(makeRequestTokenizedEmailSchema, []);
|
|
124
|
+
|
|
125
|
+
const { requestChangeEmail, error, setError, resetErrors, saving } =
|
|
126
|
+
useRequestChangeEmail({
|
|
127
|
+
onCompleted: (data: any) => {
|
|
128
|
+
if (data.requestChangeEmail) {
|
|
129
|
+
setWaitingForVerification(true);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const onSubmit = (fv: any) => {
|
|
135
|
+
requestChangeEmail({
|
|
136
|
+
variables: {
|
|
137
|
+
emailAddress: fv.email,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
if (waitingForVerification) {
|
|
143
|
+
return (
|
|
144
|
+
<ModalSimpleContent
|
|
145
|
+
className="px_df pt_md pb_25"
|
|
146
|
+
iconName={COMMON_ICON_NAMES.email_address}
|
|
147
|
+
title={i18n.t('auth.check_email')}
|
|
148
|
+
message={i18n.t('auth.check_email_to_login_msg')}
|
|
149
|
+
/>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return (
|
|
154
|
+
<>
|
|
155
|
+
<p className="a_c mx_df mb_df -mt_5 pb_xs">
|
|
156
|
+
{i18n.t('auth.add_email_to_login_msg', { identifier })}
|
|
157
|
+
</p>
|
|
158
|
+
|
|
159
|
+
<SchemaForm
|
|
160
|
+
className="pb_df fs"
|
|
161
|
+
saving={saving}
|
|
162
|
+
schema={assignPasswordSchema}
|
|
163
|
+
// currentData={{}}
|
|
164
|
+
onError={setError}
|
|
165
|
+
onSubmit={onSubmit}
|
|
166
|
+
buttonText={i18n.t('auth.add_email')}
|
|
167
|
+
>
|
|
168
|
+
{!error ? null : (
|
|
169
|
+
<ModalErrorMessage error={error} resetErrors={resetErrors} />
|
|
170
|
+
)}
|
|
171
|
+
</SchemaForm>
|
|
172
|
+
</>
|
|
173
|
+
);
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
/**
|
|
@@ -172,16 +178,16 @@ function SetEmailForm(p: RequiredAuthSwitchCaseProps) {
|
|
|
172
178
|
*/
|
|
173
179
|
|
|
174
180
|
function RequiredAuthSwitchCase(p: RequiredAuthSwitchCaseProps) {
|
|
175
|
-
|
|
181
|
+
const { finishedResult } = p;
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
if (!finishedResult.hasPassword) {
|
|
184
|
+
return <SetPasswordForm {...p} />;
|
|
185
|
+
} else if (!finishedResult.email) {
|
|
186
|
+
// Keep email check last, becuase it has a verification step
|
|
187
|
+
return <SetEmailForm {...p} />;
|
|
188
|
+
}
|
|
183
189
|
|
|
184
|
-
|
|
190
|
+
return <AccountSecuredMessage {...p} />;
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
/**
|
|
@@ -189,40 +195,46 @@ function RequiredAuthSwitchCase(p: RequiredAuthSwitchCaseProps) {
|
|
|
189
195
|
*/
|
|
190
196
|
|
|
191
197
|
export function AssignRequiredAuth(p: {
|
|
192
|
-
|
|
193
|
-
|
|
198
|
+
hasPassword: boolean;
|
|
199
|
+
hasEmail: boolean;
|
|
194
200
|
}) {
|
|
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
|
-
|
|
201
|
+
const {
|
|
202
|
+
dispatchApp,
|
|
203
|
+
appState: { hasPassword, account },
|
|
204
|
+
} = useContext(AppContext);
|
|
205
|
+
const identifier =
|
|
206
|
+
account?.email?.address || account?.phone?.number || account?.id;
|
|
207
|
+
|
|
208
|
+
const [finishedResult, setFinishedResult] = useState({
|
|
209
|
+
hasPassword,
|
|
210
|
+
email: account?.email?.address ? account?.email : null,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const onFinish = () => {
|
|
214
|
+
if (!hasPassword) {
|
|
215
|
+
dispatchApp({
|
|
216
|
+
__type: 'APP_EDIT_AUTH',
|
|
217
|
+
data: {
|
|
218
|
+
id: account?.id,
|
|
219
|
+
...finishedResult,
|
|
220
|
+
},
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<FullPageLayout className="pattern_dot active_bf bg_fade">
|
|
227
|
+
<AuthFormContainer
|
|
228
|
+
title={i18n.t('auth.one_last_step_')}
|
|
229
|
+
className="bd_5 bd_main"
|
|
230
|
+
>
|
|
231
|
+
<RequiredAuthSwitchCase
|
|
232
|
+
identifier={identifier!}
|
|
233
|
+
finishedResult={finishedResult}
|
|
234
|
+
setFinishedResult={setFinishedResult}
|
|
235
|
+
onFinish={onFinish}
|
|
236
|
+
/>
|
|
237
|
+
</AuthFormContainer>
|
|
238
|
+
</FullPageLayout>
|
|
239
|
+
);
|
|
228
240
|
}
|
|
@@ -8,38 +8,38 @@ import { memo } from 'react';
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
interface AuthFormContainerProps {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
title?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
backHref?: string | null;
|
|
14
|
+
children: React.ReactNode;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export const AuthFormContainer = memo((p: AuthFormContainerProps) => {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const { title, className, backHref, children } = p;
|
|
19
|
+
const goBackLabel = backHref ? i18n.t('form.go_back') : '';
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
21
|
+
return (
|
|
22
|
+
<div className="cw xs">
|
|
23
|
+
{!!backHref && (
|
|
24
|
+
<a
|
|
25
|
+
href={backHref}
|
|
26
|
+
aria-label={goBackLabel}
|
|
27
|
+
title={goBackLabel}
|
|
28
|
+
className="abs_tl_df av av_df r h_center bg cl_df bg_active_hv shadow_line z2 link"
|
|
29
|
+
>
|
|
30
|
+
<Icon name="arrow-left" />
|
|
31
|
+
</a>
|
|
32
|
+
)}
|
|
33
|
+
<div className="a_c -mb_5 anim_lift_scale_center on_mount spd_4">
|
|
34
|
+
<h1 className="ft_lg ft_bold ls_1 lh_1 p_n cl_secondary op_50 visible">
|
|
35
|
+
{title}
|
|
36
|
+
</h1>
|
|
37
|
+
</div>
|
|
38
|
+
<div className={cn('bg px_md py_lg r_dfw rel z2', className)}>
|
|
39
|
+
{children}
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
45
|
AuthFormContainer.displayName = 'AuthFormContainer';
|