@jsb188/auth-web 1.1.10 → 1.1.12
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 +27 -25
- package/src/hooks/use-auth-popup.ts +167 -0
- package/src/hooks/use-google-one-tap.ts +138 -0
- package/src/hooks/use-oauth.tsx +314 -310
- package/src/main.ts +11 -0
- package/src/modules/AssignRequiredAuth.tsx +217 -171
- package/src/modules/AuthFormUI.tsx +28 -28
- package/src/modules/AuthForms-SSO.tsx +174 -152
- package/src/modules/AuthForms.tsx +814 -612
- package/src/modules/AuthGate.tsx +93 -85
- package/src/modules/ConfirmPublicFormEmailCode.tsx +144 -0
- package/src/modules/InlineAuthForm.tsx +441 -130
- package/src/modules/ManagedSessions.tsx +86 -80
- package/src/modules/OtherAuthButtons.tsx +72 -68
- package/src/modules/_helpers.ts +161 -86
- package/src/modules/schemas.ts +159 -260
- package/src/schemas/account.ts +106 -154
- package/src/schemas/address.ts +125 -157
- package/src/ui/ManagedSessionUI.tsx +70 -64
- package/src/utils/authPopup.ts +95 -0
- package/src/utils/googleIdentity.ts +100 -0
package/src/main.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
export * from './hooks/use-auth-popup';
|
|
1
2
|
export * from './hooks/use-oauth';
|
|
3
|
+
export * from './hooks/use-google-one-tap';
|
|
4
|
+
export { suppressGoogleAutoSignIn } from './utils/googleIdentity';
|
|
5
|
+
export {
|
|
6
|
+
getAuthReturnQuery,
|
|
7
|
+
getAuthReturnContext,
|
|
8
|
+
getPublicFormReturnContext,
|
|
9
|
+
hydrateAuthenticationSession,
|
|
10
|
+
persistSignInSession,
|
|
11
|
+
} from './modules/_helpers';
|
|
2
12
|
export * from './modules/AssignRequiredAuth';
|
|
3
13
|
export * from './modules/AuthForms';
|
|
4
14
|
export * from './modules/AuthFormUI';
|
|
@@ -8,3 +18,4 @@ export * from './modules/ManagedSessions';
|
|
|
8
18
|
export * from './modules/OtherAuthButtons';
|
|
9
19
|
export * from './modules/schemas';
|
|
10
20
|
export * from './ui/ManagedSessionUI';
|
|
21
|
+
export * from './utils/authPopup';
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
2
|
import { useRequestChangeEmail } from '@jsb188/graphql/hooks/use-account-mtn';
|
|
3
|
-
import { useChangeAccountPassword } from '@jsb188/graphql/hooks/use-auth-mtn';
|
|
3
|
+
import { useChangeAccountPassword, useRequestTokenizedEmail } from '@jsb188/graphql/hooks/use-auth-mtn';
|
|
4
|
+
import { AppContext } from '@jsb188/react/states';
|
|
4
5
|
import { FullPageLayout } from '@jsb188/react-web/modules/layout/MainLayout';
|
|
5
|
-
import SchemaForm from '@jsb188/
|
|
6
|
+
import SchemaForm from '@jsb188/form/libs/SchemaForm';
|
|
7
|
+
import { submissionResult } from '@jsb188/form/libs/validation';
|
|
6
8
|
import { COMMON_ICON_NAMES } from '@jsb188/react-web/svgs/Icon';
|
|
7
9
|
import { FullWidthButton } from '@jsb188/react-web/ui/Button';
|
|
8
10
|
import Markdown from '@jsb188/react-web/ui/Markdown';
|
|
9
11
|
import { ModalErrorMessage, ModalSimpleContent } from '@jsb188/react-web/ui/ModalUI';
|
|
10
|
-
import { AppContext } from '@jsb188/react/states';
|
|
11
12
|
import { useContext, useMemo, useState } from 'react';
|
|
12
13
|
import { AuthFormContainer } from './AuthFormUI';
|
|
13
14
|
import { makeAssignPasswordSchema, makeRequestTokenizedEmailSchema } from './schemas';
|
|
@@ -17,15 +18,16 @@ import { makeAssignPasswordSchema, makeRequestTokenizedEmailSchema } from './sch
|
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
interface FinishedResultObj {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
hasPassword: boolean;
|
|
22
|
+
email: any;
|
|
23
|
+
emailVerified: boolean;
|
|
24
|
+
}
|
|
23
25
|
|
|
24
26
|
interface RequiredAuthSwitchCaseProps {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
identifier: string;
|
|
28
|
+
onFinish: () => void;
|
|
29
|
+
finishedResult: FinishedResultObj;
|
|
30
|
+
setFinishedResult: any;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -33,25 +35,25 @@ interface RequiredAuthSwitchCaseProps {
|
|
|
33
35
|
*/
|
|
34
36
|
|
|
35
37
|
function AccountSecuredMessage(p: RequiredAuthSwitchCaseProps) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
const { onFinish } = p;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ModalSimpleContent
|
|
42
|
+
// title='Finished!'
|
|
43
|
+
iconName={COMMON_ICON_NAMES.verified}
|
|
44
|
+
className="px_df pt_md"
|
|
45
|
+
>
|
|
46
|
+
<Markdown as="p">{i18n.t('auth.required_auth_fin_msg')}</Markdown>
|
|
47
|
+
|
|
48
|
+
<FullWidthButton
|
|
49
|
+
preset="bg_primary"
|
|
50
|
+
className="mt_md shadow"
|
|
51
|
+
onClick={onFinish}
|
|
52
|
+
>
|
|
53
|
+
{i18n.t('auth.continue_to_app')}
|
|
54
|
+
</FullWidthButton>
|
|
55
|
+
</ModalSimpleContent>
|
|
56
|
+
);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/**
|
|
@@ -59,53 +61,53 @@ function AccountSecuredMessage(p: RequiredAuthSwitchCaseProps) {
|
|
|
59
61
|
*/
|
|
60
62
|
|
|
61
63
|
function SetPasswordForm(p: RequiredAuthSwitchCaseProps) {
|
|
64
|
+
const { identifier, setFinishedResult } = p;
|
|
65
|
+
const assignPasswordSchema = useMemo(makeAssignPasswordSchema, []);
|
|
62
66
|
|
|
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
|
-
</SchemaForm>
|
|
108
|
-
</>;
|
|
67
|
+
const { changeAccountPassword, saving, error, setError, resetErrors } = useChangeAccountPassword({
|
|
68
|
+
doNotFinishForm: true,
|
|
69
|
+
onCompleted: (passwordChanged: boolean) => {
|
|
70
|
+
if (passwordChanged) {
|
|
71
|
+
setFinishedResult((fr: FinishedResultObj) => ({
|
|
72
|
+
...fr,
|
|
73
|
+
hasPassword: true,
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/* Await the password mutation before completing this form step. */
|
|
80
|
+
const onSubmit = async (fv: { password: string; passwordRepeat: string }) => {
|
|
81
|
+
const result = await changeAccountPassword({
|
|
82
|
+
variables: {
|
|
83
|
+
currentPassword: '',
|
|
84
|
+
password: fv.password,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return submissionResult(result);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<p className="a_c mx_df mb_df -mt_5 pb_xs">{i18n.t('auth.add_password_sign_in_msg', { identifier })}</p>
|
|
93
|
+
|
|
94
|
+
<SchemaForm
|
|
95
|
+
className="pb_df fs"
|
|
96
|
+
busy={saving}
|
|
97
|
+
definition={assignPasswordSchema}
|
|
98
|
+
onError={setError}
|
|
99
|
+
onSubmit={onSubmit}
|
|
100
|
+
buttonText={i18n.t('auth.add_password')}
|
|
101
|
+
>
|
|
102
|
+
{!error ? null : (
|
|
103
|
+
<ModalErrorMessage
|
|
104
|
+
error={error}
|
|
105
|
+
resetErrors={resetErrors}
|
|
106
|
+
/>
|
|
107
|
+
)}
|
|
108
|
+
</SchemaForm>
|
|
109
|
+
</>
|
|
110
|
+
);
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
/**
|
|
@@ -113,58 +115,98 @@ function SetPasswordForm(p: RequiredAuthSwitchCaseProps) {
|
|
|
113
115
|
*/
|
|
114
116
|
|
|
115
117
|
function SetEmailForm(p: RequiredAuthSwitchCaseProps) {
|
|
118
|
+
const { finishedResult, identifier } = p;
|
|
119
|
+
const [waitingForVerification, setWaitingForVerification] = useState(false);
|
|
120
|
+
const assignPasswordSchema = useMemo(makeRequestTokenizedEmailSchema, []);
|
|
121
|
+
const existingEmailAddress = finishedResult.email?.address || '';
|
|
122
|
+
const currentData = useMemo(() => ({ email: existingEmailAddress }), [existingEmailAddress]);
|
|
123
|
+
const requiresExistingEmailVerification = !!existingEmailAddress && !finishedResult.emailVerified;
|
|
124
|
+
|
|
125
|
+
/*
|
|
126
|
+
* Show the check-email state after either email request succeeds.
|
|
127
|
+
*/
|
|
128
|
+
const onEmailRequested = (result: any) => {
|
|
129
|
+
if (result?.requestChangeEmail || result?.requestTokenizedEmail) {
|
|
130
|
+
setWaitingForVerification(true);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
116
133
|
|
|
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
|
-
|
|
134
|
+
const changeEmail = useRequestChangeEmail();
|
|
135
|
+
const verifyEmail = useRequestTokenizedEmail();
|
|
136
|
+
const error = changeEmail.error || verifyEmail.error;
|
|
137
|
+
const saving = changeEmail.saving || verifyEmail.saving;
|
|
138
|
+
|
|
139
|
+
/*
|
|
140
|
+
* Clear errors from both possible email-request mutations.
|
|
141
|
+
*/
|
|
142
|
+
const resetErrors = () => {
|
|
143
|
+
changeEmail.resetErrors();
|
|
144
|
+
verifyEmail.resetErrors();
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/*
|
|
148
|
+
* Send a verification link for the current address, or a change-email link
|
|
149
|
+
* when the user supplies a different address.
|
|
150
|
+
*/
|
|
151
|
+
const onSubmit = async (fv: { email: string }) => {
|
|
152
|
+
const emailAddress = fv.email.trim();
|
|
153
|
+
if (emailAddress.toLowerCase() === existingEmailAddress.trim().toLowerCase()) {
|
|
154
|
+
const result = await verifyEmail.requestTokenizedEmail({
|
|
155
|
+
variables: {
|
|
156
|
+
email: emailAddress,
|
|
157
|
+
requestType: 'EMAIL_VERIFICATION',
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
onEmailRequested(result);
|
|
161
|
+
return submissionResult(result);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const result = await changeEmail.requestChangeEmail({
|
|
165
|
+
variables: {
|
|
166
|
+
emailAddress,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
onEmailRequested(result);
|
|
170
|
+
return submissionResult(result);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
if (waitingForVerification) {
|
|
174
|
+
return (
|
|
175
|
+
<ModalSimpleContent
|
|
176
|
+
className="px_df pt_md pb_25"
|
|
177
|
+
iconName={COMMON_ICON_NAMES.email_address}
|
|
178
|
+
title={i18n.t('auth.check_email')}
|
|
179
|
+
message={i18n.t('auth.check_email_to_login_msg')}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<>
|
|
186
|
+
<p className="a_c mx_df mb_df -mt_5 pb_xs">
|
|
187
|
+
{i18n.t(requiresExistingEmailVerification ? 'auth.verify_email_to_login_msg' : 'auth.add_email_to_login_msg', {
|
|
188
|
+
identifier,
|
|
189
|
+
})}
|
|
190
|
+
</p>
|
|
191
|
+
|
|
192
|
+
<SchemaForm
|
|
193
|
+
className="pb_df fs"
|
|
194
|
+
initialValues={currentData}
|
|
195
|
+
busy={saving}
|
|
196
|
+
definition={assignPasswordSchema}
|
|
197
|
+
onError={changeEmail.setError}
|
|
198
|
+
onSubmit={onSubmit}
|
|
199
|
+
buttonText={i18n.t(requiresExistingEmailVerification ? 'auth.resend_verification' : 'auth.add_email')}
|
|
200
|
+
>
|
|
201
|
+
{!error ? null : (
|
|
202
|
+
<ModalErrorMessage
|
|
203
|
+
error={error}
|
|
204
|
+
resetErrors={resetErrors}
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
</SchemaForm>
|
|
208
|
+
</>
|
|
209
|
+
);
|
|
168
210
|
}
|
|
169
211
|
|
|
170
212
|
/**
|
|
@@ -172,57 +214,61 @@ function SetEmailForm(p: RequiredAuthSwitchCaseProps) {
|
|
|
172
214
|
*/
|
|
173
215
|
|
|
174
216
|
function RequiredAuthSwitchCase(p: RequiredAuthSwitchCaseProps) {
|
|
175
|
-
|
|
217
|
+
const { finishedResult } = p;
|
|
176
218
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
if (!finishedResult.hasPassword) {
|
|
220
|
+
return <SetPasswordForm {...p} />;
|
|
221
|
+
}
|
|
222
|
+
if (!finishedResult.emailVerified) {
|
|
223
|
+
// Keep the email check last because it has a verification step.
|
|
224
|
+
return <SetEmailForm {...p} />;
|
|
225
|
+
}
|
|
183
226
|
|
|
184
|
-
|
|
227
|
+
return <AccountSecuredMessage {...p} />;
|
|
185
228
|
}
|
|
186
229
|
|
|
187
230
|
/**
|
|
188
231
|
* Force users to provide required authentication info
|
|
189
232
|
*/
|
|
190
233
|
|
|
191
|
-
export function AssignRequiredAuth(p: {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
234
|
+
export function AssignRequiredAuth(p: { hasPassword: boolean; hasVerifiedEmail: boolean }) {
|
|
235
|
+
const {
|
|
236
|
+
dispatchApp,
|
|
237
|
+
appState: { hasPassword, account },
|
|
238
|
+
} = useContext(AppContext);
|
|
239
|
+
const identifier = account?.email?.address || account?.phone?.number || account?.id;
|
|
240
|
+
|
|
241
|
+
const [finishedResult, setFinishedResult] = useState({
|
|
242
|
+
hasPassword,
|
|
243
|
+
email: account?.email?.address ? account?.email : null,
|
|
244
|
+
emailVerified: p.hasVerifiedEmail,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const onFinish = () => {
|
|
248
|
+
if (!hasPassword) {
|
|
249
|
+
dispatchApp({
|
|
250
|
+
__type: 'APP_EDIT_AUTH',
|
|
251
|
+
data: {
|
|
252
|
+
id: account?.id,
|
|
253
|
+
...finishedResult,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<FullPageLayout className="pattern_dot active_bf bg_fade">
|
|
261
|
+
<AuthFormContainer
|
|
262
|
+
title={i18n.t('auth.one_last_step_')}
|
|
263
|
+
className="bd_5 bd_main"
|
|
264
|
+
>
|
|
265
|
+
<RequiredAuthSwitchCase
|
|
266
|
+
identifier={identifier!}
|
|
267
|
+
finishedResult={finishedResult}
|
|
268
|
+
setFinishedResult={setFinishedResult}
|
|
269
|
+
onFinish={onFinish}
|
|
270
|
+
/>
|
|
271
|
+
</AuthFormContainer>
|
|
272
|
+
</FullPageLayout>
|
|
273
|
+
);
|
|
228
274
|
}
|
|
@@ -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('c.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={cn("ft_lg ft_bold ls_1 lh_1 p_n cl_secondary op_50 visible", !title && 'mt_25')}>
|
|
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';
|