'My web is not sending email verification via Firebase but my then function or error functions not triggering
I am working on html and java script project but when i try sendSignInLinkToEmail its not sending the email and both then and catch are not triggering
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const database = getDatabase(app);
const auth = getAuth();
var attachment = document.getElementById('attachment');
attachment.onchange = () => {
const selectedFile = attachment.files[0];
}
register.addEventListener('click', (e) => {
var fname = document.getElementById("fname-field").value;
var lname = document.getElementById("lname-field").value;
var birthdate = document.getElementById("birthdate-field").value;
var passport = document.getElementById("passport-field").value;
var email = document.getElementById("email-field").value;
var areacode = document.getElementById("country-select").value;
var phoneNumber = document.getElementById("phonenumber-field").value;
var country = document.getElementById("country-field");
var nation = document.getElementById("nation-field").value;
var emergencyname = document.getElementById("emergencyname-field").value;
var emergencyrelation = document.getElementById("emergencyrelation-field").value;
var emergencyinfo = document.getElementById("emergencyinfo-field").value;
var attachment = document.getElementById('attachment');
var persentage = document.getElementById('persentage');
createUserWithEmailAndPassword(auth, email, nation)
.then((userCredential) => {
// Signed in
const user = userCredential.user;
set(ref(database, 'users/' + user.uid), {
FirstName: fname,
LastName: lname,
Birthdate: birthdate,
PassportNumber: passport,
Email: email,
PhoneNumber: phoneNumber,
Country: country,
Nationality: nation,
EmergencyName: emergencyname,
EmergencyRelation: emergencyrelation,
EmergencyInfo: emergencyinfo
});
async function UploadAttachment() {
var selectedFile = attachment.files[0];
var fileName = user.uid
const metaData = {
contentType: selectedFile.type
}
const storage = getStorage();
const storageRef = sRef(storage, "attachments/" + fileName)
const UploadTask = uploadBytesResumable(storageRef, selectedFile, metaData);
UploadTask.on('state-changed', (snapshot) => {
var uploadProgress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
persentage.innerHTML = "Upload" + uploadProgress + "%";
},(error) => {
alert('error: Image Not Uploaded')
},
()=>{
getDownloadURL(UploadTask.snapshot.ref).then((downloadUrl) => {
console.log(downloadUrl);
})
}
);
}
UploadAttachment();
// ...
console.log("usersigned up");
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ..
alert(errorMessage);
});
const actionCodeSettings = {
// URL you want to redirect back to. The domain (www.example.com) for this
// URL must be in the authorized domains list in the Firebase Console.
// This must be true.
handleCodeInApp: true,
};
sendSignInLinkToEmail(auth, email, actionCodeSettings)
.then(() => {
// The link was successfully sent. Inform the user.
// Save the email locally so you don't need to ask the user for it again
// if they open the link on the same device.
console.log("Email Sent");
window.localStorage.setItem('emailForSignIn', email);
// ...
})
.catch((error) => {
const errorCode = error.code;
const errorMessage = error.message;
// ...
}
);
});
Solution 1:[1]
You may have forgotten to add actionCodeSettings parameter to sendSignInLinkToEmail
If not try to
- Use devtools breakpoints
- Check network tab if there is any requests are going to server
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ratakondala Arun |
