/home/techb158/workloadmatch.com/js
Edit: /home/techb158/workloadmatch.com/js/firebase-otp.js (2376B)
var otpRecaptchaVerifier = null;
var otpConfirmationResult = null;
function initOtpRecaptcha() {
if (otpRecaptchaVerifier) return;
otpRecaptchaVerifier = new firebase.auth.RecaptchaVerifier('otp-recaptcha-container', {
'size': 'invisible',
'callback': function () { }
});
}
function autoSendOtp() {
if (!otpPhoneNumber) return;
initOtpRecaptcha();
firebase.auth().signInWithPhoneNumber(otpPhoneNumber, otpRecaptchaVerifier)
.then(function (confirmationResult) {
otpConfirmationResult = confirmationResult;
})
.catch(function (error) {
var errDiv = document.getElementById('otp-code-error');
errDiv.textContent = 'Failed to send OTP: ' + error.message;
errDiv.style.display = 'block';
console.error('Firebase OTP send error:', error);
});
}
function verifyForgotOtp() {
var codeInput = document.getElementById('otp-code');
var verifyBtn = document.getElementById('otp-verify-btn');
var codeError = document.getElementById('otp-code-error');
var code = codeInput.value.trim();
codeError.style.display = 'none';
if (!code || code.length < 6) {
codeError.textContent = 'Please enter the 6-digit code.';
codeError.style.display = 'block';
return;
}
if (!otpConfirmationResult) {
codeError.textContent = 'No OTP was sent. Please refresh and try again.';
codeError.style.display = 'block';
return;
}
verifyBtn.disabled = true;
verifyBtn.textContent = 'Verifying...';
otpConfirmationResult.confirm(code)
.then(function (result) {
result.user.getIdToken().then(function (idToken) {
document.getElementById('id_token_input').value = idToken;
document.getElementById('otp-form').submit();
});
})
.catch(function (error) {
verifyBtn.disabled = false;
verifyBtn.textContent = 'Verify Code';
codeError.textContent = 'Invalid code. Please try again.';
codeError.style.display = 'block';
console.error('Firebase OTP verify error:', error);
});
}
window.addEventListener('load', function () {
if (typeof otpPhoneNumber !== 'undefined' && otpPhoneNumber) {
setTimeout(autoSendOtp, 500);
}
});