I am trying to set up sign up and login functionality to my website but I am having some issues. I am running the website in live browser from vs code. I can see the email accounts that have been created within my firebase console. However, when I try to login to an account using on of those accounts on the website, it says that no account exists. If I then try to sign up using the same email, it says the account already exists. Im pretty new to this so the problem may be obvious but I cant seem to figure it out.
loginButton.addEventListener('click', () => {
authMenu.style.display = 'flex';
createAccountMenu.style.display = 'none';
});
createAccountButton.addEventListener('click', () => {
authMenu.style.display = 'none';
createAccountMenu.style.display = 'flex';
});
backToLoginButton.addEventListener('click', () => {
authMenu.style.display = 'flex';
createAccountMenu.style.display = 'none';
});
authActionButton.addEventListener('click', async (event) => {
event.preventDefault();
const email = emailField.value;
const password = passwordField.value;
if (!email) {
messageElement.textContent = 'Please enter your email.';
return;
}
if (!password) {
messageElement.textContent = 'Please enter your password.';
return;
}
try {
const methods = await fetchSignInMethodsForEmail(auth, email);
if (methods.length === 0) {
messageElement.textContent = 'Email is not registered. Please create an account.';
return;
}
await signInWithEmailAndPassword(auth, email, password);
messageElement.textContent = 'Signed in successfully!';
authMenu.style.display = 'none';
} catch (error) {
messageElement.textContent = `Error: ${error.message}`;
}
});
createAccountActionButton.addEventListener('click', async (event) => {
event.preventDefault();
const email = createEmailField.value;
const password = createPasswordField.value;
if (!email) {
createAccountMessageElement.textContent = 'Please enter your email.';
return;
}
if (!password) {
createAccountMessageElement.textContent = 'Please enter your password.';
return;
}
try {
await createUserWithEmailAndPassword(auth, email, password);
createAccountMessageElement.textContent = 'Account created successfully!';
createAccountMenu.style.display = 'none';
} catch (error) {
createAccountMessageElement.textContent = `Error: ${error.message}`;
}
});
I’m also not sure what other details you may need to help so if theres anything else please just let me know.