Проблема, с которой я столкнулся, заключается в том, что после успешной аутентификации пользователя в Firebase (без ошибок в консоли отладки браузера) файл JS не перенаправляет на вторую страницу. Я следую коду, предоставленному firebase, и тоже искал в github. На данный момент я не уверен, что мне не хватает. заранее спасибо за помощь.
<!DOCTYPE html>
<html>
<head>
<div>
<title>My Page</title>
<h1>test</h1>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="author" content="Name"
<link href="https://fonts.googleapis.com/css?family=Nunito:400,600,700" rel="stylesheet">
<link rel="stylesheet" href="style.css" />
</div>
<script src="https://www.gstatic.com/firebasejs/5.11.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.11.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/5.11.0/firebase-database.js"></script>
<script>
var config = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(config);
</script>
<script src="webapp.js"></script>
</head>
<body>
<div class="main-div">
<h2>Test2</h2>
<input id="txtEmail" type="email" placeholder="Email..." />
<input id="txtPass" type="password" placeholder="Password..." />
<button type="button" onclick="login()" >Login Here</button>
<div>
</body>
</html>
.JS file
function login() {
email = document.getElementById('txtEmail').value;
password = document.getElementById('txtPass').value;
loginBtn = document.getElementById('loginBtn');`enter code here`
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
var errorCode = error.code;
var errorMessage = error.message;
if (errorCode === 'auth/wrong-password') {
alert('Wrong password, try again!.');
} else {
alert(errorMessage);
}
console.log(error);
});
}
function initApp() {
firebase.auth().onAuthStateChanged(function(user) {
if(user) {
// User is signed in
window.location = 'secondpage.html';
} else {
alert('test!.');
}
}
)}