So I’m trying to make a signup/login system. The signup page works, when I click the sign up button it sends me to the homepage (RAB.html). But when I go to the log in page and click the log in button, it errors. “This page isn’t working, HTTP ERROR 405”. What seems to be the problem?
I’m using firebase btw
this is my code:
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.1.0/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/11.1.0/firebase-analytics.js";
import {getAuth, createUserWithEmailAndPassword, signInWithEmailAndPassword} from "https://www.gstatic.com/firebasejs/11.1.0/firebase-auth.js"
import {getFirestore, setDoc, doc} from "https://www.gstatic.com/firebasejs/11.1.0/firebase-firestore.js"
const firebaseConfig = {
apiKey: "AIzaSyBhDkEUta73LDAm-Zah0vU-uGpVRTN6PaA",
authDomain: "rabp-6ae41.firebaseapp.com",
projectId: "rabp-6ae41",
storageBucket: "rabp-6ae41.firebasestorage.app",
messagingSenderId: "124825740643",
appId: "1:124825740643:web:1b888d74e3adfd15575f56",
measurementId: "G-EYVYX974MD"
};
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
function showMessage(message, divId) {
var messageDiv=document.getElementById(divId);
messageDiv.style.display="block";
messageDiv.innerHTML=message;
messageDiv.style.opacity=1;
setTimeout(function(){
messageDiv.style.opacity=0;
},5000);
}
const signUp=document.getElementById('submitSignUp');
signUp.addEventListener('click', (event)=>{
event.preventDefault();
const email=document.getElementById('rEmail').value;
const password=document.getElementById('rPassword').value;
const firstName=document.getElementById('fName').value;
const lastName=document.getElementById('lName').value;
const address=document.getElementById('rAddress').value;
const number=document.getElementById('rNumber').value;
const auth=getAuth();
const db=getFirestore();
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential)=>{
const user=userCredential.user;
const userData= {
email: email,
firstName: firstName,
lastName: lastName,
address: address,
number: number
};
showMessage('Account Created Successfully', 'signUpMessage');
const docRef=doc(db, "users", user.uid);
setDoc(docRef,userData)
.then(()=>{
window.location.href='RAB.html';
})
.catch((error)=>{
console.error("error writing document", error);
});
})
.catch((error)=> {
const errorCode=error.code;
if(errorCode=='auth/email-already-in-use'){
showMessage('Email Address Already Exists !!!', 'signUpMessage')
} else {
showMessage('unable to create User', 'signUpMessage');
}
})
})
const signIn = document.getElementById('submitSignIn');
signIn.addEventListener('click', (event)=>{
event.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const auth = getAuth();
signInWithEmailAndPassword(auth, email, password)
.then((userCredential)=>{
showMessage('login is successful', 'signInMessage');
const user=userCredential.user;
localStorage.setItem('loggedInUserId', user.uid);
window.location.href='RAB.html';
})
.catch((error)=>{
const errorCode=error.code;
if(errorCode ==='auth/invalid-credential'){
showMessage('Incorrect Email or Password', 'signInMessage');
} else {
showMessage('Account does not Exist', 'signInMessage')
}
})
})