@jsb188/auth-web 1.1.12 → 1.1.13
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/LICENSE +21 -0
- package/package.json +16 -8
- package/src/hooks/use-auth-popup.ts +2 -27
- package/src/hooks/use-oauth.tsx +64 -118
- package/src/main.ts +0 -3
- package/src/modules/AuthForms-SSO.tsx +6 -14
- package/src/modules/AuthForms.tsx +52 -107
- package/src/modules/InlineAuthForm.tsx +57 -122
- package/src/modules/ManagedSessions.tsx +6 -3
- package/src/modules/OtherAuthButtons.tsx +23 -30
- package/src/modules/_helpers.ts +1 -23
- package/src/schemas/address.ts +10 -4
- package/src/utils/authPopup.ts +0 -60
- package/src/utils/googleIdentity.ts +6 -61
- package/src/hooks/use-google-one-tap.ts +0 -138
- package/src/modules/ConfirmPublicFormEmailCode.tsx +0 -144
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
useSendPhoneVerificationCode,
|
|
9
9
|
useSignUpWithEmail,
|
|
10
10
|
} from '@jsb188/graphql/hooks/use-auth-mtn';
|
|
11
|
-
import { useSendPublicFormEmailCode } from '@jsb188/graphql/hooks/use-publicFormEmail-mtn';
|
|
12
11
|
import { SMSCodeInput } from '@jsb188/form/modules/Form';
|
|
13
12
|
import SchemaForm from '@jsb188/form/libs/SchemaForm';
|
|
14
13
|
import { submissionResult } from '@jsb188/form/libs/validation';
|
|
@@ -23,7 +22,6 @@ import { getAuthPopupCompletionPath } from '../utils/authPopup.ts';
|
|
|
23
22
|
import type { AuthPageName } from './_helpers';
|
|
24
23
|
import { getAuthReturnQuery, getAuthRoute, persistSignInSession } from './_helpers';
|
|
25
24
|
import { SsoSignIn } from './AuthForms-SSO';
|
|
26
|
-
import { ConfirmPublicFormEmailCode } from './ConfirmPublicFormEmailCode';
|
|
27
25
|
import { ContinueWithGoogle, ContinueWithMicrosoft, ContinueWithPhone, ContinueWithSso } from './OtherAuthButtons';
|
|
28
26
|
import {
|
|
29
27
|
type SignInFormValues,
|
|
@@ -49,9 +47,6 @@ export const meta = [
|
|
|
49
47
|
|
|
50
48
|
interface AuthFormProps {
|
|
51
49
|
appNamespace: string;
|
|
52
|
-
formPublicId?: string | null;
|
|
53
|
-
allowPublicFormEmail?: boolean;
|
|
54
|
-
onPublicFormRespondentVerified?: (token: string, email: string | null) => boolean;
|
|
55
50
|
initialMethod?: 'PHONE';
|
|
56
51
|
initialError?: any;
|
|
57
52
|
initialFormData?: any;
|
|
@@ -70,7 +65,7 @@ interface AuthFormProps {
|
|
|
70
65
|
}
|
|
71
66
|
|
|
72
67
|
/*
|
|
73
|
-
* Preserve
|
|
68
|
+
* Preserve return and popup context across one authentication navigation.
|
|
74
69
|
*/
|
|
75
70
|
function getAuthNavigationQuery(returnTo?: string | null, popupMode?: boolean, popupId?: string | null) {
|
|
76
71
|
const searchParams = new URLSearchParams(getAuthReturnQuery(returnTo));
|
|
@@ -95,16 +90,14 @@ function getSignInSuccessRoute(p: Pick<AuthFormProps, 'authRoutesMap' | 'popupId
|
|
|
95
90
|
}
|
|
96
91
|
|
|
97
92
|
/*
|
|
98
|
-
* Discover existing accounts
|
|
93
|
+
* Discover existing accounts before choosing the verification screen.
|
|
99
94
|
*/
|
|
100
95
|
const SignInMain = (p: AuthFormProps) => {
|
|
101
|
-
const { authRoutesMap,
|
|
96
|
+
const { authRoutesMap, initialError, initialFormData, popupId, popupMode, returnTo, setAuthIface } = p;
|
|
102
97
|
const navigate = useNavigate();
|
|
103
98
|
const [waitingForPostRequest, setWaitingForPostRequest] = useState(false);
|
|
104
99
|
const mounted = useRef(true);
|
|
105
100
|
const signInSchema = useMemo(makeSignInSchema, []);
|
|
106
|
-
const allowPublicFormEmail = !!p.allowPublicFormEmail && !!formPublicId && !!p.onPublicFormRespondentVerified;
|
|
107
|
-
const { sendPublicFormEmailCode, saving: sendingEmailCode } = useSendPublicFormEmailCode();
|
|
108
101
|
const { saving, checkUsernameOrEmail, dataForSchema, setDataForSchema, error, setError, resetErrors } = useCheckUsernameOrEmail({
|
|
109
102
|
initialError,
|
|
110
103
|
initialFormData: {
|
|
@@ -155,7 +148,7 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
155
148
|
const response = await checkUsernameOrEmail({
|
|
156
149
|
variables: {
|
|
157
150
|
usernameOrEmail: identifier,
|
|
158
|
-
authCheck:
|
|
151
|
+
authCheck: true,
|
|
159
152
|
},
|
|
160
153
|
});
|
|
161
154
|
if (!mounted.current) {
|
|
@@ -183,26 +176,6 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
183
176
|
break;
|
|
184
177
|
case 'EMAIL':
|
|
185
178
|
if (!result.taken) {
|
|
186
|
-
if (allowPublicFormEmail) {
|
|
187
|
-
const email = identifier.toLowerCase();
|
|
188
|
-
const sent = await sendPublicFormEmailCode({ variables: { formPublicId, email } });
|
|
189
|
-
if (!mounted.current) {
|
|
190
|
-
return { status: 'continue' };
|
|
191
|
-
}
|
|
192
|
-
if (getValues().identifier.trim() !== identifier) {
|
|
193
|
-
resetErrors();
|
|
194
|
-
return { status: 'continue' };
|
|
195
|
-
}
|
|
196
|
-
const sendSubmission = submissionResult(sent);
|
|
197
|
-
if (sendSubmission.status !== 'success') {
|
|
198
|
-
return sendSubmission;
|
|
199
|
-
}
|
|
200
|
-
if (!sent?.sendPublicFormEmailCode) {
|
|
201
|
-
return { status: 'error', error: { message: i18n.t('error.30000') } };
|
|
202
|
-
}
|
|
203
|
-
setAuthIface(['VERIFY_PUBLIC_FORM_EMAIL_SENT', email]);
|
|
204
|
-
return { status: 'continue' };
|
|
205
|
-
}
|
|
206
179
|
return { status: 'error', error: { message: i18n.t('auth.no_account_with_email') } };
|
|
207
180
|
}
|
|
208
181
|
break;
|
|
@@ -270,8 +243,8 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
270
243
|
const agentLoginFooter =
|
|
271
244
|
agentLoginAvailable && !hidePassword ? (
|
|
272
245
|
<FullWidthButton
|
|
273
|
-
className=
|
|
274
|
-
preset=
|
|
246
|
+
className="mt_sm"
|
|
247
|
+
preset="bg_secondary"
|
|
275
248
|
loading={agentLoginSaving}
|
|
276
249
|
onClick={onClickAgentLogin}
|
|
277
250
|
>
|
|
@@ -283,32 +256,26 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
283
256
|
<>
|
|
284
257
|
{popupMode ? null : (
|
|
285
258
|
<>
|
|
286
|
-
<ContinueWithGoogle
|
|
287
|
-
|
|
288
|
-
onFinishSignIn={onFinishSignIn}
|
|
289
|
-
/>
|
|
290
|
-
<ContinueWithMicrosoft
|
|
291
|
-
formPublicId={formPublicId}
|
|
292
|
-
onFinishSignIn={onFinishSignIn}
|
|
293
|
-
/>
|
|
259
|
+
<ContinueWithGoogle onFinishSignIn={onFinishSignIn} />
|
|
260
|
+
<ContinueWithMicrosoft onFinishSignIn={onFinishSignIn} />
|
|
294
261
|
<ContinueWithSso onClickButton={() => setAuthIface('SSO')} />
|
|
295
262
|
</>
|
|
296
263
|
)}
|
|
297
264
|
<ContinueWithPhone onClickButton={() => setAuthIface('VERIFY_PHONE')} />
|
|
298
265
|
|
|
299
266
|
<FormBreak
|
|
300
|
-
className=
|
|
301
|
-
colorClassName=
|
|
267
|
+
className="mt_md"
|
|
268
|
+
colorClassName="strong_bf"
|
|
302
269
|
>
|
|
303
270
|
{i18n.t('c.or')}
|
|
304
271
|
</FormBreak>
|
|
305
272
|
|
|
306
273
|
<SchemaForm
|
|
307
|
-
method=
|
|
274
|
+
method="post"
|
|
308
275
|
actionUrl={getAuthRoute('signin', authRoutesMap, getAuthNavigationQuery(returnTo, popupMode, popupId))}
|
|
309
|
-
className=
|
|
276
|
+
className="py_df"
|
|
310
277
|
initialValues={{ identifier: initialFormData?.identifier || '' }}
|
|
311
|
-
busy={saving ||
|
|
278
|
+
busy={saving || waitingForPostRequest}
|
|
312
279
|
definition={signInSchema}
|
|
313
280
|
context={dataForSchema}
|
|
314
281
|
onSubmit={onSubmit}
|
|
@@ -317,9 +284,9 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
317
284
|
FooterComponent={agentLoginFooter}
|
|
318
285
|
>
|
|
319
286
|
<input
|
|
320
|
-
type=
|
|
321
|
-
name=
|
|
322
|
-
value=
|
|
287
|
+
type="hidden"
|
|
288
|
+
name="managedSessionVersion"
|
|
289
|
+
value="1"
|
|
323
290
|
/>
|
|
324
291
|
{error && (
|
|
325
292
|
<ModalErrorMessage
|
|
@@ -331,10 +298,10 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
331
298
|
</SchemaForm>
|
|
332
299
|
|
|
333
300
|
{!showSignUpLink || !popupMode ? (
|
|
334
|
-
<div className=
|
|
301
|
+
<div className="a_c">
|
|
335
302
|
{showSignUpLink ? (
|
|
336
303
|
<Link
|
|
337
|
-
className=
|
|
304
|
+
className="text_link ft_sm cl_md link"
|
|
338
305
|
to={getAuthRoute('signup', authRoutesMap, getAuthNavigationQuery(returnTo, popupMode, popupId))}
|
|
339
306
|
replace
|
|
340
307
|
>
|
|
@@ -342,8 +309,8 @@ const SignInMain = (p: AuthFormProps) => {
|
|
|
342
309
|
</Link>
|
|
343
310
|
) : (
|
|
344
311
|
<button
|
|
345
|
-
type=
|
|
346
|
-
className=
|
|
312
|
+
type="button"
|
|
313
|
+
className="text_link ft_sm cl_md link"
|
|
347
314
|
onClick={() => setAuthIface('REQUEST_PASSWORD_RESET')}
|
|
348
315
|
>
|
|
349
316
|
{i18n.t('auth.forgot_password_')}
|
|
@@ -440,7 +407,7 @@ function RequestTokenizedEmail(p: RequestTokenizedEmailProps) {
|
|
|
440
407
|
)}
|
|
441
408
|
|
|
442
409
|
<Markdown
|
|
443
|
-
as=
|
|
410
|
+
as="p"
|
|
444
411
|
className={error ? 'py_xs a_c' : '-mt_5 pb_xs a_c'}
|
|
445
412
|
>
|
|
446
413
|
{instructionText}
|
|
@@ -464,12 +431,12 @@ function ResetPasswordCompleted(p: AuthFormProps) {
|
|
|
464
431
|
return (
|
|
465
432
|
<ModalSimpleContent
|
|
466
433
|
title={i18n.t('auth.email_sent')}
|
|
467
|
-
iconName=
|
|
434
|
+
iconName="circle-check"
|
|
468
435
|
>
|
|
469
|
-
<TextWithLinks as=
|
|
436
|
+
<TextWithLinks as="p">
|
|
470
437
|
{i18n.t(emailAddress ? 'auth.reset_password_requested_msg' : 'auth.reset_password_requested_msg_no_email', { emailAddress })}
|
|
471
438
|
</TextWithLinks>
|
|
472
|
-
<TextWithLinks as=
|
|
439
|
+
<TextWithLinks as="p">{i18n.t('auth.if_need_more_help_email', { emailAddress: supportEmail })}</TextWithLinks>
|
|
473
440
|
</ModalSimpleContent>
|
|
474
441
|
);
|
|
475
442
|
}
|
|
@@ -509,7 +476,7 @@ function SendPhoneVerification(p: AuthFormProps) {
|
|
|
509
476
|
return (
|
|
510
477
|
<>
|
|
511
478
|
<SchemaForm
|
|
512
|
-
className=
|
|
479
|
+
className="mb_df"
|
|
513
480
|
busy={saving}
|
|
514
481
|
definition={sendPhoneVerificationSchema}
|
|
515
482
|
onError={setError}
|
|
@@ -526,12 +493,12 @@ function SendPhoneVerification(p: AuthFormProps) {
|
|
|
526
493
|
<p className={error ? 'py_xs a_c' : '-mt_5 pb_xs a_c'}>{i18n.t('auth.send_verification_code_msg')}</p>
|
|
527
494
|
</SchemaForm>
|
|
528
495
|
|
|
529
|
-
<div className=
|
|
496
|
+
<div className="a_c h_center">
|
|
530
497
|
<button
|
|
531
|
-
type=
|
|
498
|
+
type="button"
|
|
532
499
|
disabled={saving}
|
|
533
500
|
onClick={() => setAuthIface(null)}
|
|
534
|
-
className=
|
|
501
|
+
className="text_link ft_sm cl_md link"
|
|
535
502
|
>
|
|
536
503
|
{i18n.t('auth.sign_in_other_methods')}
|
|
537
504
|
</button>
|
|
@@ -607,13 +574,13 @@ function ConfirmPhoneVerificationCode(p: ConfirmPhoneVerificationCodeProps) {
|
|
|
607
574
|
error={error}
|
|
608
575
|
onSubmit={onSubmit}
|
|
609
576
|
/>
|
|
610
|
-
<p className=
|
|
611
|
-
<div className=
|
|
577
|
+
<p className="a_c p_n mt_md mb_df rel">{i18n.t('auth.confirm_verification_code_instr')}</p>
|
|
578
|
+
<div className="a_c h_center">
|
|
612
579
|
<button
|
|
613
|
-
type=
|
|
580
|
+
type="button"
|
|
614
581
|
disabled={saving}
|
|
615
582
|
onClick={() => setAuthIface('VERIFY_PHONE')}
|
|
616
|
-
className=
|
|
583
|
+
className="text_link ft_sm cl_md link"
|
|
617
584
|
>
|
|
618
585
|
{i18n.t('auth.resend_verification_code')}
|
|
619
586
|
</button>
|
|
@@ -633,7 +600,6 @@ type SignInIface =
|
|
|
633
600
|
| 'VERIFY_EMAIL'
|
|
634
601
|
| 'EMAIL_SENT'
|
|
635
602
|
| 'VERIFY_PHONE_SENT'
|
|
636
|
-
| ['VERIFY_PUBLIC_FORM_EMAIL_SENT', string]
|
|
637
603
|
| ['VERIFY_PHONE_SENT', string];
|
|
638
604
|
|
|
639
605
|
export function SignInForm(p: Omit<AuthFormProps, 'setAuthIface'>) {
|
|
@@ -644,22 +610,7 @@ export function SignInForm(p: Omit<AuthFormProps, 'setAuthIface'>) {
|
|
|
644
610
|
const [signInIface_, setAuthIface] = useState<SignInIface | null>(initialIface);
|
|
645
611
|
const ifaceIsArray = Array.isArray(signInIface_);
|
|
646
612
|
|
|
647
|
-
/* Return changed public-form emails to account discovery before choosing their authentication method. */
|
|
648
|
-
const onReturnToSignIn = () => setAuthIface(null);
|
|
649
|
-
|
|
650
613
|
switch (ifaceIsArray ? signInIface_[0] : signInIface_) {
|
|
651
|
-
case 'VERIFY_PUBLIC_FORM_EMAIL_SENT':
|
|
652
|
-
if (!p.allowPublicFormEmail || !p.formPublicId || !p.onPublicFormRespondentVerified) {
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
655
|
-
return (
|
|
656
|
-
<ConfirmPublicFormEmailCode
|
|
657
|
-
formPublicId={p.formPublicId}
|
|
658
|
-
email={ifaceIsArray ? signInIface_[1] : ''}
|
|
659
|
-
onRespondentToken={p.onPublicFormRespondentVerified}
|
|
660
|
-
onChangeEmail={onReturnToSignIn}
|
|
661
|
-
/>
|
|
662
|
-
);
|
|
663
614
|
case 'SSO':
|
|
664
615
|
// Email-first SSO sign in (org home realm discovery)
|
|
665
616
|
return (
|
|
@@ -690,7 +641,7 @@ export function SignInForm(p: Omit<AuthFormProps, 'setAuthIface'>) {
|
|
|
690
641
|
return (
|
|
691
642
|
<RequestTokenizedEmail
|
|
692
643
|
{...p}
|
|
693
|
-
requestType=
|
|
644
|
+
requestType="EMAIL_VERIFICATION"
|
|
694
645
|
setAuthIface={setAuthIface}
|
|
695
646
|
/>
|
|
696
647
|
);
|
|
@@ -698,7 +649,7 @@ export function SignInForm(p: Omit<AuthFormProps, 'setAuthIface'>) {
|
|
|
698
649
|
return (
|
|
699
650
|
<RequestTokenizedEmail
|
|
700
651
|
{...p}
|
|
701
|
-
requestType=
|
|
652
|
+
requestType="PASSWORD_RESET"
|
|
702
653
|
setAuthIface={setAuthIface}
|
|
703
654
|
/>
|
|
704
655
|
);
|
|
@@ -730,7 +681,7 @@ interface SignUpMainProps extends Omit<AuthFormProps, 'setAuthIface'> {
|
|
|
730
681
|
}
|
|
731
682
|
|
|
732
683
|
function SignUpMain(p: SignUpMainProps) {
|
|
733
|
-
const { authRoutesMap,
|
|
684
|
+
const { authRoutesMap, initialError, returnTo, setAuthIface, setSignUpToken } = p;
|
|
734
685
|
const navigate = useNavigate();
|
|
735
686
|
const signUpSchema = useMemo(makeSignUpSchema, []);
|
|
736
687
|
|
|
@@ -776,24 +727,18 @@ function SignUpMain(p: SignUpMainProps) {
|
|
|
776
727
|
|
|
777
728
|
return (
|
|
778
729
|
<>
|
|
779
|
-
<ContinueWithGoogle
|
|
780
|
-
|
|
781
|
-
onFinishSignIn={onFinishSignIn}
|
|
782
|
-
/>
|
|
783
|
-
<ContinueWithMicrosoft
|
|
784
|
-
formPublicId={formPublicId}
|
|
785
|
-
onFinishSignIn={onFinishSignIn}
|
|
786
|
-
/>
|
|
730
|
+
<ContinueWithGoogle onFinishSignIn={onFinishSignIn} />
|
|
731
|
+
<ContinueWithMicrosoft onFinishSignIn={onFinishSignIn} />
|
|
787
732
|
|
|
788
733
|
<FormBreak
|
|
789
|
-
className=
|
|
790
|
-
colorClassName=
|
|
734
|
+
className="mt_md"
|
|
735
|
+
colorClassName="strong_bf"
|
|
791
736
|
>
|
|
792
737
|
{i18n.t('c.or')}
|
|
793
738
|
</FormBreak>
|
|
794
739
|
|
|
795
740
|
<SchemaForm
|
|
796
|
-
className=
|
|
741
|
+
className="py_df"
|
|
797
742
|
busy={saving}
|
|
798
743
|
definition={signUpSchema}
|
|
799
744
|
onError={setError}
|
|
@@ -801,9 +746,9 @@ function SignUpMain(p: SignUpMainProps) {
|
|
|
801
746
|
buttonText={i18n.t('auth.agree_and_continue')}
|
|
802
747
|
FooterComponent={
|
|
803
748
|
<TextWithLinks
|
|
804
|
-
as=
|
|
805
|
-
className=
|
|
806
|
-
linkClassName=
|
|
749
|
+
as="div"
|
|
750
|
+
className="ft_xs mt_sm cl_md"
|
|
751
|
+
linkClassName="u link cl_md"
|
|
807
752
|
>
|
|
808
753
|
{i18n.t('auth.sign_up_notice_msg')}
|
|
809
754
|
</TextWithLinks>
|
|
@@ -818,11 +763,11 @@ function SignUpMain(p: SignUpMainProps) {
|
|
|
818
763
|
)}
|
|
819
764
|
</SchemaForm>
|
|
820
765
|
|
|
821
|
-
<div className=
|
|
766
|
+
<div className="a_c h_center">
|
|
822
767
|
<Link
|
|
823
768
|
to={getAuthRoute('signin', authRoutesMap, getAuthReturnQuery(returnTo))}
|
|
824
769
|
replace
|
|
825
|
-
className=
|
|
770
|
+
className="text_link ft_sm cl_md link"
|
|
826
771
|
>
|
|
827
772
|
{i18n.t('auth.sign_in_w_existing')}
|
|
828
773
|
</Link>
|
|
@@ -841,9 +786,9 @@ function SignUpInviteRequired(_p: Omit<AuthFormProps, 'setAuthIface'>) {
|
|
|
841
786
|
return (
|
|
842
787
|
<ModalSimpleContent
|
|
843
788
|
title={i18n.t('auth.invite_required')}
|
|
844
|
-
iconName=
|
|
789
|
+
iconName="mailbox-filled"
|
|
845
790
|
>
|
|
846
|
-
<TextWithLinks as=
|
|
791
|
+
<TextWithLinks as="p">{i18n.t('auth.invite_required_msg', { emailAddress: supportEmail })}</TextWithLinks>
|
|
847
792
|
</ModalSimpleContent>
|
|
848
793
|
);
|
|
849
794
|
}
|
|
@@ -862,15 +807,15 @@ function SignUpSuccess(p: SignUpSuccessProps) {
|
|
|
862
807
|
return (
|
|
863
808
|
<ModalSimpleContent
|
|
864
809
|
title={i18n.t('auth.account_created')}
|
|
865
|
-
iconName=
|
|
866
|
-
className=
|
|
810
|
+
iconName="circle-check"
|
|
811
|
+
className="px_df pt_md"
|
|
867
812
|
>
|
|
868
|
-
<TextWithLinks as=
|
|
813
|
+
<TextWithLinks as="p">{i18n.t('auth.account_created_msg')}</TextWithLinks>
|
|
869
814
|
|
|
870
815
|
<FullWidthButton
|
|
871
816
|
to={getAuthRoute('signin', authRoutesMap, getAuthReturnQuery(returnTo))}
|
|
872
|
-
preset=
|
|
873
|
-
className=
|
|
817
|
+
preset="bg_primary"
|
|
818
|
+
className="mt_lg shadow"
|
|
874
819
|
replace
|
|
875
820
|
>
|
|
876
821
|
{i18n.t('auth.continue_to_login')}
|