我正在尝试将我的网站连接到Firebase数据库,并通过Firebase身份验证对用户进行身份验证。但是我从一开始就感到震惊。我的网站托管在Firebase中,因此我尝试自动初始化Firebase。我放置了测试警报,以检查Firebase身份验证是否正常运行。页面正在加载,并且没有问题:
这是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>****</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script src="/__/firebase/7.20.0/firebase-app.js"></script>
<script src="/__/firebase/7.20.-/firebase-auth.js"></script>
<script src="/__/firebase/7.20.-/firebase-analytics.js"></script>
<script src="/__/firebase/init.js"></script>
<script>
window.onload = function() {
alert("Page Loaded");
// Listening for auth state changes.
firebase.auth().onAuthStateChanged(function(user) {
alert("Firebase Connected");
if (user) {
// User is signed in.
} else {
// No user is signed in.
}
});
}
</script>
</body>
</html>
页面加载警报触发,但Firebase Connected警报不触发