@@ -718,6 +718,7 @@ function clearApplicationVerifier() {
718
718
* Sends a phone number verification code for sign-in.
719
719
*/
720
720
function onSignInVerifyPhoneNumber ( ) {
721
+ console . log ( 'onSignInVerifyPhoneNumber with ApplicationVerifier' ) ;
721
722
const phoneNumber = $ ( '#signin-phone-number' ) . val ( ) ;
722
723
const provider = new PhoneAuthProvider ( auth ) ;
723
724
// Clear existing reCAPTCHA as an existing reCAPTCHA could be targeted for a
@@ -738,6 +739,31 @@ function onSignInVerifyPhoneNumber() {
738
739
) ;
739
740
}
740
741
742
+ /**
743
+ * Sends a phone number verification code for sign-in.
744
+ */
745
+ function onSignInVerifyPhoneNumberNoAppVerifier ( ) {
746
+ console . log ( 'onSignInVerifyPhoneNumber without ApplicationVerifier' ) ;
747
+ const phoneNumber = $ ( '#signin-phone-number' ) . val ( ) ;
748
+ const provider = new PhoneAuthProvider ( auth ) ;
749
+ // Clear existing reCAPTCHA as an existing reCAPTCHA could be targeted for a
750
+ // link/re-auth operation.
751
+ clearApplicationVerifier ( ) ;
752
+ // Initialize a reCAPTCHA application verifier.
753
+ makeApplicationVerifier ( 'signin-verify-phone-number' ) ;
754
+ provider . verifyPhoneNumber ( phoneNumber ) . then (
755
+ verificationId => {
756
+ clearApplicationVerifier ( ) ;
757
+ $ ( '#signin-phone-verification-id' ) . val ( verificationId ) ;
758
+ alertSuccess ( 'Phone verification sent!' ) ;
759
+ } ,
760
+ error => {
761
+ clearApplicationVerifier ( ) ;
762
+ onAuthError ( error ) ;
763
+ }
764
+ ) ;
765
+ }
766
+
741
767
/**
742
768
* Confirms a phone number verification for sign-in.
743
769
*/
@@ -831,6 +857,7 @@ function onReauthConfirmPhoneVerification() {
831
857
* Sends a phone number verification code for enrolling second factor.
832
858
*/
833
859
function onStartEnrollWithPhoneMultiFactor ( ) {
860
+ console . log ( 'onStartEnrollWithPhoneMultiFactor with ApplicationVerifier' ) ;
834
861
const phoneNumber = $ ( '#enroll-mfa-phone-number' ) . val ( ) ;
835
862
if ( ! phoneNumber || ! activeUser ( ) ) {
836
863
return ;
@@ -863,6 +890,40 @@ function onStartEnrollWithPhoneMultiFactor() {
863
890
) ;
864
891
}
865
892
893
+ function onStartEnrollWithPhoneMultiFactorNoAppVerifier ( ) {
894
+ console . log ( 'onStartEnrollWithPhoneMultiFactor without ApplicationVerifier' ) ;
895
+ const phoneNumber = $ ( '#enroll-mfa-phone-number' ) . val ( ) ;
896
+ if ( ! phoneNumber || ! activeUser ( ) ) {
897
+ return ;
898
+ }
899
+ const provider = new PhoneAuthProvider ( auth ) ;
900
+ // Clear existing reCAPTCHA as an existing reCAPTCHA could be targeted for a
901
+ // sign-in operation.
902
+ clearApplicationVerifier ( ) ;
903
+ // Initialize a reCAPTCHA application verifier.
904
+ makeApplicationVerifier ( 'enroll-mfa-verify-phone-number' ) ;
905
+ multiFactor ( activeUser ( ) )
906
+ . getSession ( )
907
+ . then ( multiFactorSession => {
908
+ const phoneInfoOptions = {
909
+ phoneNumber,
910
+ 'session' : multiFactorSession
911
+ } ;
912
+ return provider . verifyPhoneNumber ( phoneInfoOptions ) ;
913
+ } )
914
+ . then (
915
+ verificationId => {
916
+ clearApplicationVerifier ( ) ;
917
+ $ ( '#enroll-mfa-phone-verification-id' ) . val ( verificationId ) ;
918
+ alertSuccess ( 'Phone verification sent!' ) ;
919
+ } ,
920
+ error => {
921
+ clearApplicationVerifier ( ) ;
922
+ onAuthError ( error ) ;
923
+ }
924
+ ) ;
925
+ }
926
+
866
927
/**
867
928
* Confirms a phone number verification for MFA enrollment.
868
929
*/
@@ -1436,6 +1497,7 @@ function onSelectMultiFactorHint(index) {
1436
1497
* @param {!jQuery.Event } event The jQuery event object.
1437
1498
*/
1438
1499
function onStartSignInWithPhoneMultiFactor ( event ) {
1500
+ console . log ( 'onStartSignInWithPhoneMultiFactor with ApplicationVerifier' ) ;
1439
1501
event . preventDefault ( ) ;
1440
1502
// Make sure a second factor is selected.
1441
1503
if ( ! selectedMultiFactorHint || ! multiFactorErrorResolver ) {
@@ -1460,6 +1522,32 @@ function onStartSignInWithPhoneMultiFactor(event) {
1460
1522
) ;
1461
1523
}
1462
1524
1525
+ function onStartSignInWithPhoneMultiFactorNoAppVerifier ( event ) {
1526
+ console . log ( 'onStartSignInWithPhoneMultiFactor without ApplicationVerifier' ) ;
1527
+ event . preventDefault ( ) ;
1528
+ // Make sure a second factor is selected.
1529
+ if ( ! selectedMultiFactorHint || ! multiFactorErrorResolver ) {
1530
+ return ;
1531
+ }
1532
+ // Initialize a reCAPTCHA application verifier.
1533
+ const provider = new PhoneAuthProvider ( auth ) ;
1534
+ const signInRequest = {
1535
+ multiFactorHint : selectedMultiFactorHint ,
1536
+ session : multiFactorErrorResolver . session
1537
+ } ;
1538
+ provider . verifyPhoneNumber ( signInRequest ) . then (
1539
+ verificationId => {
1540
+ clearApplicationVerifier ( ) ;
1541
+ $ ( '#multi-factor-sign-in-verification-id' ) . val ( verificationId ) ;
1542
+ alertSuccess ( 'Phone verification sent!' ) ;
1543
+ } ,
1544
+ error => {
1545
+ clearApplicationVerifier ( ) ;
1546
+ onAuthError ( error ) ;
1547
+ }
1548
+ ) ;
1549
+ }
1550
+
1463
1551
/**
1464
1552
* Completes sign-in with the 2nd factor phone assertion.
1465
1553
* @param {!jQuery.Event } event The jQuery event object.
@@ -2275,6 +2363,7 @@ function initApp() {
2275
2363
onSignInWithGenericIdPCredential
2276
2364
) ;
2277
2365
$ ( '#signin-verify-phone-number' ) . click ( onSignInVerifyPhoneNumber ) ;
2366
+ $ ( '#signin-verify-phone-number-no-appverifier' ) . click ( onSignInVerifyPhoneNumberNoAppVerifier ) ;
2278
2367
$ ( '#signin-confirm-phone-verification' ) . click (
2279
2368
onSignInConfirmPhoneVerification
2280
2369
) ;
@@ -2364,6 +2453,7 @@ function initApp() {
2364
2453
// Multi-factor operations.
2365
2454
// Starts multi-factor sign-in with selected phone number.
2366
2455
$ ( '#send-2fa-phone-code' ) . click ( onStartSignInWithPhoneMultiFactor ) ;
2456
+ $ ( '#send-2fa-phone-code-no-appverifier' ) . click ( onStartSignInWithPhoneMultiFactorNoAppVerifier ) ;
2367
2457
// Completes multi-factor sign-in with supplied SMS code.
2368
2458
$ ( '#sign-in-with-phone-multi-factor' ) . click (
2369
2459
onFinalizeSignInWithPhoneMultiFactor
@@ -2376,6 +2466,7 @@ function initApp() {
2376
2466
2377
2467
// Starts multi-factor enrollment with phone number.
2378
2468
$ ( '#enroll-mfa-verify-phone-number' ) . click ( onStartEnrollWithPhoneMultiFactor ) ;
2469
+ $ ( '#enroll-mfa-verify-phone-number-no-appverifier' ) . click ( onStartEnrollWithPhoneMultiFactorNoAppVerifier ) ;
2379
2470
// Completes multi-factor enrollment with supplied SMS code.
2380
2471
$ ( '#enroll-mfa-confirm-phone-verification' ) . click (
2381
2472
onFinalizeEnrollWithPhoneMultiFactor
0 commit comments