I have create a Realtime database below]1]1
I just want a code to check if the inputed email exist in the database. An alert should be shown to the user.
My code so far though not working thanks
export default function Login() {
const [email, setEmail] = useState('');
const handleSubmit = (e) => {
const db = getDatabase(app);
const dbRef = ref(db, "nature/");
const query = dbRef.orderByChild('email').equalTo('email');
query.once('value', function(snapshot) {
if (snapshot.exists()) {
alert("login")
} else {
alert("notloged")
}
});
};
return (
<form onSubmit={handleSubmit}>
<div>
<label>Email:</label>
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
<button type="submit">Login</button>
</form>
);
}