const firebaseConfig = {
apiKey: "AIzaSyDaegpDT8MPNmsdWJuPT1w3YG5reON4ApA",
authDomain: "trulora-woo-store.firebaseapp.com",
projectId: "trulora-woo-store",
};
firebase.initializeApp(firebaseConfig);
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-app.js";
import { getAuth, RecaptchaVerifier, signInWithPhoneNumber } from "https://www.gstatic.com/firebasejs/10.7.1/firebase-auth.js";
let confirmationResult;
jQuery(function($){
const auth = firebase.auth();
// Setup reCAPTCHA
window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier('recaptcha-container', {
size: 'normal'
}, auth);
$('#send-otp').click(function(){
let phoneNumber = $('#phone').val();
auth.signInWithPhoneNumber(phoneNumber, window.recaptchaVerifier)
.then(function(result){
confirmationResult = result;
alert('OTP sent');
})
.catch(function(error){
console.error(error);
alert('Error sending OTP');
});
});
$('#verify-otp').click(function(){
let code = $('#otp').val();
confirmationResult.confirm(code).then(function(result){
let user = result.user;
let phone = user.phoneNumber;
// Hide OTP section
$('#otp-section').hide();
// Show checkout
$('#checkout-section').show();
// Autofill WooCommerce phone field
$('#billing_phone').val(phone);
// Trigger Woo update
$(document.body).trigger('update_checkout');
}).catch(function(error){
alert('Invalid OTP');
});
});
});
$('#billing_phone').val(phone);
Skip to main content
Skip to footer