auth/phone-invisible.html [162:255]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
window.signingIn = true;
updateSignInButtonUI();
var phoneNumber = getPhoneNumberFromUserInput();
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
window.signingIn = false;
updateSignInButtonUI();
updateVerificationCodeFormUI();
updateVerifyCodeButtonUI();
updateSignInFormUI();
}).catch(function (error) {
// Error; SMS not sent
console.error('Error during signInWithPhoneNumber', error);
window.alert('Error during signInWithPhoneNumber:\n\n'
+ error.code + '\n\n' + error.message);
window.signingIn = false;
updateSignInFormUI();
updateSignInButtonUI();
});
}
}
/**
* Function called when clicking the "Verify Code" button.
*/
function onVerifyCodeSubmit(e) {
e.preventDefault();
if (!!getCodeFromUserInput()) {
window.verifyingCode = true;
updateVerifyCodeButtonUI();
var code = getCodeFromUserInput();
confirmationResult.confirm(code).then(function (result) {
// User signed in successfully.
var user = result.user;
window.verifyingCode = false;
window.confirmationResult = null;
updateVerificationCodeFormUI();
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
console.error('Error while checking the verification code', error);
window.alert('Error while checking the verification code:\n\n'
+ error.code + '\n\n' + error.message);
window.verifyingCode = false;
updateSignInButtonUI();
updateVerifyCodeButtonUI();
});
}
}
/**
* Cancels the verification code input.
*/
function cancelVerification(e) {
e.preventDefault();
window.confirmationResult = null;
updateVerificationCodeFormUI();
updateSignInFormUI();
}
/**
* Signs out the user when the sign-out button is clicked.
*/
function onSignOutClick() {
firebase.auth().signOut();
}
/**
* Reads the verification code from the user input.
*/
function getCodeFromUserInput() {
return document.getElementById('verification-code').value;
}
/**
* Reads the phone number from the user input.
*/
function getPhoneNumberFromUserInput() {
return document.getElementById('phone-number').value;
}
/**
* Returns true if the phone number is valid.
*/
function isPhoneNumberValid() {
var pattern = /^\+[0-9\s\-\(\)]+$/;
var phoneNumber = getPhoneNumberFromUserInput();
return phoneNumber.search(pattern) !== -1;
}
/**
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
auth/phone-visible.html [170:263]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
window.signingIn = true;
updateSignInButtonUI();
var phoneNumber = getPhoneNumberFromUserInput();
var appVerifier = window.recaptchaVerifier;
firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)
.then(function (confirmationResult) {
// SMS sent. Prompt user to type the code from the message, then sign the
// user in with confirmationResult.confirm(code).
window.confirmationResult = confirmationResult;
window.signingIn = false;
updateSignInButtonUI();
updateVerificationCodeFormUI();
updateVerifyCodeButtonUI();
updateSignInFormUI();
}).catch(function (error) {
// Error; SMS not sent
console.error('Error during signInWithPhoneNumber', error);
window.alert('Error during signInWithPhoneNumber:\n\n'
+ error.code + '\n\n' + error.message);
window.signingIn = false;
updateSignInFormUI();
updateSignInButtonUI();
});
}
}
/**
* Function called when clicking the "Verify Code" button.
*/
function onVerifyCodeSubmit(e) {
e.preventDefault();
if (!!getCodeFromUserInput()) {
window.verifyingCode = true;
updateVerifyCodeButtonUI();
var code = getCodeFromUserInput();
confirmationResult.confirm(code).then(function (result) {
// User signed in successfully.
var user = result.user;
window.verifyingCode = false;
window.confirmationResult = null;
updateVerificationCodeFormUI();
}).catch(function (error) {
// User couldn't sign in (bad verification code?)
console.error('Error while checking the verification code', error);
window.alert('Error while checking the verification code:\n\n'
+ error.code + '\n\n' + error.message);
window.verifyingCode = false;
updateSignInButtonUI();
updateVerifyCodeButtonUI();
});
}
}
/**
* Cancels the verification code input.
*/
function cancelVerification(e) {
e.preventDefault();
window.confirmationResult = null;
updateVerificationCodeFormUI();
updateSignInFormUI();
}
/**
* Signs out the user when the sign-out button is clicked.
*/
function onSignOutClick() {
firebase.auth().signOut();
}
/**
* Reads the verification code from the user input.
*/
function getCodeFromUserInput() {
return document.getElementById('verification-code').value;
}
/**
* Reads the phone number from the user input.
*/
function getPhoneNumberFromUserInput() {
return document.getElementById('phone-number').value;
}
/**
* Returns true if the phone number is valid.
*/
function isPhoneNumberValid() {
var pattern = /^\+[0-9\s\-\(\)]+$/;
var phoneNumber = getPhoneNumberFromUserInput();
return phoneNumber.search(pattern) !== -1;
}
/**
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -