Я разработал страницу входа (через firebase).После успешного входа в систему я хочу получить доступ к домашней странице. Но она показывает эту ошибку (ReferenceError: firebase не определена) в терминале. Согласно моему мнению, ошибка заключается в инициализации базы данных firebase. Любой, пожалуйста, помогите мне избавиться от этой ошибки.
Вот мой index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/style.css" />
<script src="https://www.gstatic.com/firebasejs/6.6.2/firebase-app.js"></script>
</head>
<body class="bg-dark">
<div id="login-card" class="card">
<div class="card-body">
<h1>Wallpaper App Admin</h1>
<form id="login-form">
<div class="form-group">
<label for="email">email</label>
<input type="email" id="email" class="form-control" />
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" class="form-control" />
</div>
<div class="form-group">
<button id="btn-login" type="button" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</div>
<script src="js/app.js"></script>
<script>
firebase.auth().onAuthStateChanged(function(user){
if(user){
window.location.href = "admin.html";
}
});
</script>
</body>
</html>
Вот мой admin.html:
<!DOCTYPE html>
<script src="https://www.gstatic.com/firebasejs/6.6.2/firebase-app.js"></script>
</head>
<body>
<h1> You are Logged in!!! </h1>
<script src="js/app.js"></script>
<script>
firebase.auth().onAuthStateChanged(function(user){
if(!user){
window.location.href = "index.html";
}
});
</script>
</body>
Вот мой файл app.js:
var firebaseConfig = {
apiKey: "API-key",
authDomain: "e-agriculture9.firebaseapp.com",
databaseURL: "https://e-agriculture9.firebaseio.com",
projectId: "e-agriculture9",
storageBucket: "",
messagingSenderId: "1086965307452",
appId: "1:1086965307452:web:ea0fd9076744c723a5cb39"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.auth.Auth.Persistence.LOCAL;
$("#btn-login").click(function(){
alert("You Clicked here!");
var email = $("#email").val();
var password = $("#password").val();
var result = firebase.auth().signInWithEmailAndPassword(email, password);
result.catch(function(error){
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
});
});
Вот моя консоль отладки:
c:\Users\hp\Desktop\WallpaperAppAdmin\public\js\app.js:11
firebase.initializeApp(firebaseConfig);
^
ReferenceError: firebase is not defined
at Object.<anonymous> (c:\Users\hp\Desktop\WallpaperAppAdmin\public \js\app.js:11:3)
at Module._compile (internal/modules/cjs/loader.js:775:14)
ReferenceError: firebase is not defined
at Object.<anonymous> (c:\Users\hp\Desktop\WallpaperAppAdmin\public \js\app.js:11:3)
at Module._compile (internal/modules/cjs/loader.js:775:14)
В соответствии с консолью Debug это критические строки кода в app.jsfile:
firebase.initializeApp(firebaseConfig);
firebase.auth.Auth.Persistence.LOCAL;
Когда я добавляю инструкцию Import в начале файла app.js, он отображается в консоли отладки:
Debugger attached.
c:\Users\hp\Desktop\WallpaperAppAdmin\public\js\app.js:1
import firebase from 'firebase'
Пожалуйста, объясните мне, как редактировать эти строки кода визбавиться от этой ошибки. Заранее спасибо.