попробуйте этот код!
проблема с вашей кнопкой.
<button click="login()">Login to Account</button>
click
не является допустимым событием, onclick
является действительным.поэтому ваша кнопка будет выглядеть так:
<button onclick="login()">Login to Account</button>
<html>
<head>
<title>TEST</title>
<h1>TESTING</h1>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Name"
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="login_div" class="main-div">
<h3>Welcome</h3>
<input id="userEmail" type="email" placeholder="Email..." />
<input id="userPassword" type="password" placeholder="Password..." />
<button onclick="login()">Login to Account</button>
</div>
<script src="https://www.gstatic.com/firebasejs/5.11.0/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "KEY",
authDomain: "name.firebaseapp.com",
databaseURL: "https://name.firebaseio.com",
projectId: "testlist",
storageBucket: "testlist.appspot.com",
messagingSenderId: "111111111111"
};
firebase.initializeApp(config);
firebase.initializeApp(config);
</script>
<script src="test.js"></script>
</body>
</html>
<_TEST.js->
function login() {
const userEmail = document.getElementById("userEmail");
const userPassword = document.getElementById("userPassword");
const email = userEmail.value;
console.log("TCL: login -> email", email);
const pass = userPassword.value;
console.log("TCL: login -> pass", pass);
firebase
.auth()
.signInWithEmailAndPassword(email, pass)
.catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === "auth/wrong-password") {
alert("Wrong password.");
} else {
alert(errorMessage);
}
console.log(error);
});
firebase.auth().onAuthStateChanged(user => {
console.log("TCL: login -> user", user);
if (user) {
window.location = "secondpage.html";
}
});
}