Skip to content

Commit c164642

Browse files
committed
Add buttons for no appVerifier
1 parent 42e4814 commit c164642

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

packages/auth/demo/public/index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@
388388
<button class="btn btn-block btn-primary" id="signin-verify-phone-number">
389389
Verify Phone Number
390390
</button>
391+
<button class="btn btn-block btn-primary" id="signin-verify-phone-number-no-appverifier">
392+
Verify Phone Number (Without reCAPTCHA v2 AppVerifier)
393+
</button>
391394
<input type="text" id="signin-phone-verification-id"
392395
class="form-control" placeholder="Phone Verification ID" />
393396
<input type="text" id="signin-phone-verification-code"
@@ -630,6 +633,9 @@
630633
<button class="btn btn-block btn-primary" id="enroll-mfa-verify-phone-number">
631634
Verify Phone Number
632635
</button>
636+
<button class="btn btn-block btn-primary" id="enroll-mfa-verify-phone-number-no-appverifier">
637+
Verify Phone Number (Without reCAPTCHA v2 AppVerifier)
638+
</button>
633639
<input type="text" id="enroll-mfa-phone-verification-id"
634640
class="form-control" placeholder="Phone Verification ID" />
635641
<input type="text" id="enroll-mfa-phone-verification-code"
@@ -875,6 +881,9 @@ <h4 class="modal-title">Select a second factor to sign in with</h4>
875881
<button class="btn btn-block btn-primary" id="send-2fa-phone-code">
876882
Send code
877883
</button>
884+
<button class="btn btn-block btn-primary" id="send-2fa-phone-code-no-appverifier">
885+
Send code (Without reCAPTCHA v2 AppVerifier)
886+
</button>
878887
</div>
879888
<div class="form">
880889
<input type="text" id="multi-factor-sign-in-verification-id"

packages/auth/demo/src/index.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ function clearApplicationVerifier() {
718718
* Sends a phone number verification code for sign-in.
719719
*/
720720
function onSignInVerifyPhoneNumber() {
721+
console.log('onSignInVerifyPhoneNumber with ApplicationVerifier');
721722
const phoneNumber = $('#signin-phone-number').val();
722723
const provider = new PhoneAuthProvider(auth);
723724
// Clear existing reCAPTCHA as an existing reCAPTCHA could be targeted for a
@@ -738,6 +739,31 @@ function onSignInVerifyPhoneNumber() {
738739
);
739740
}
740741

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+
741767
/**
742768
* Confirms a phone number verification for sign-in.
743769
*/
@@ -831,6 +857,7 @@ function onReauthConfirmPhoneVerification() {
831857
* Sends a phone number verification code for enrolling second factor.
832858
*/
833859
function onStartEnrollWithPhoneMultiFactor() {
860+
console.log('onStartEnrollWithPhoneMultiFactor with ApplicationVerifier');
834861
const phoneNumber = $('#enroll-mfa-phone-number').val();
835862
if (!phoneNumber || !activeUser()) {
836863
return;
@@ -863,6 +890,40 @@ function onStartEnrollWithPhoneMultiFactor() {
863890
);
864891
}
865892

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+
866927
/**
867928
* Confirms a phone number verification for MFA enrollment.
868929
*/
@@ -1436,6 +1497,7 @@ function onSelectMultiFactorHint(index) {
14361497
* @param {!jQuery.Event} event The jQuery event object.
14371498
*/
14381499
function onStartSignInWithPhoneMultiFactor(event) {
1500+
console.log('onStartSignInWithPhoneMultiFactor with ApplicationVerifier');
14391501
event.preventDefault();
14401502
// Make sure a second factor is selected.
14411503
if (!selectedMultiFactorHint || !multiFactorErrorResolver) {
@@ -1460,6 +1522,32 @@ function onStartSignInWithPhoneMultiFactor(event) {
14601522
);
14611523
}
14621524

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+
14631551
/**
14641552
* Completes sign-in with the 2nd factor phone assertion.
14651553
* @param {!jQuery.Event} event The jQuery event object.
@@ -2275,6 +2363,7 @@ function initApp() {
22752363
onSignInWithGenericIdPCredential
22762364
);
22772365
$('#signin-verify-phone-number').click(onSignInVerifyPhoneNumber);
2366+
$('#signin-verify-phone-number-no-appverifier').click(onSignInVerifyPhoneNumberNoAppVerifier);
22782367
$('#signin-confirm-phone-verification').click(
22792368
onSignInConfirmPhoneVerification
22802369
);
@@ -2364,6 +2453,7 @@ function initApp() {
23642453
// Multi-factor operations.
23652454
// Starts multi-factor sign-in with selected phone number.
23662455
$('#send-2fa-phone-code').click(onStartSignInWithPhoneMultiFactor);
2456+
$('#send-2fa-phone-code-no-appverifier').click(onStartSignInWithPhoneMultiFactorNoAppVerifier);
23672457
// Completes multi-factor sign-in with supplied SMS code.
23682458
$('#sign-in-with-phone-multi-factor').click(
23692459
onFinalizeSignInWithPhoneMultiFactor
@@ -2376,6 +2466,7 @@ function initApp() {
23762466

23772467
// Starts multi-factor enrollment with phone number.
23782468
$('#enroll-mfa-verify-phone-number').click(onStartEnrollWithPhoneMultiFactor);
2469+
$('#enroll-mfa-verify-phone-number-no-appverifier').click(onStartEnrollWithPhoneMultiFactorNoAppVerifier);
23792470
// Completes multi-factor enrollment with supplied SMS code.
23802471
$('#enroll-mfa-confirm-phone-verification').click(
23812472
onFinalizeEnrollWithPhoneMultiFactor

0 commit comments

Comments
 (0)