xxxxxxxxxx
const emailExists = (email) => {
// Assuming you have already initialized Firebase and have a reference to the Firebase database
return new Promise((resolve, reject) => {
const emailRef = firebase.database().ref('users').orderByChild('email').equalTo(email);
// Listen for value changes in the emailRef
emailRef.on('value', (snapshot) => {
if (snapshot.exists()) {
resolve(true); // Email exists in the database
} else {
resolve(false); // Email does not exist in the database
}
}, (error) => {
reject(error); // Error occurred while checking email existence
});
});
};
// Usage:
emailExists('example@example.com')
.then((exists) => {
console.log(exists); // true if email exists, false otherwise
})
.catch((error) => {
console.error(error); // Handle error
});