在多个页面上保持联系

我无法让用户帐户在多个页面上保持连接状态,我想做的是,当用户进行身份验证时,他将被重定向到加载了数据的另一个页面,但是我不能这样做,因为他们没有上传到其他页面。

data is not loaded: enter image description here

我的代码js:

var authEmailPassButton = document.getElementById('authEmailPassButton') 
var logOutButton = document.getElementById('logOutButton')
var emailInput = document.getElementById('emailInput')
var passwordInput = document.getElementById('passwordInput')


authEmailPassButton.addEventListener('click', function(){
    firebase
    .auth()
    .signInWithEmailAndPassword(emailInput.value, passwordInput.value)
    .then(function(result){
        console.log(result)
        alert('Welcome')
    })
.catch(function (error){
    console.error(error.code)
    console.error(erro.message)
    alert('Failed to authenticate, check the console for the error!')
})
})

firebase.auth().onAuthStateChanged(function(user){
if (user) {

    var user = firebase.auth().currentUser;

     if (user != null) {
        var email = user.email;
        var emailVerified = user.emailVerified;
        var uid = user.uid
        displayName.innerText = 'Welcome, ' + email
        window.location = 'home.html'
    }         

} else {
    console.log('Not connected')
}
})


 logOutButton.addEventListener('click', function(){
firebase
.auth().signOut()
.then(function (){
        alert('You disconnected')
}, function(error){
        console.error(error)
    })
})

我的代码html:

<html>
<head>
    <title>Firebase</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta http-equiv="Content-Type" content="text/html"; charset="utf-8">

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>

<body>
    <div class="w3-bar w3-border w3-light-grey" style="background-color: white;">
        <a href="#" class="w3-bar-item w3-button w3-green">Home</a>
        <a href="#" class="w3-bar-item w3-button">News</a>
        <a href="#" class="w3-bar-item w3-button">profile setting</a>
        <a href="#" class="w3-bar-item w3-button">Form</a>
      </div> 
      <h3 class="text-center" id="displayName">You are not authenticated</h3>


    <!-- The core Firebase JS SDK is always required and must be listed first -->
    <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
    
    <script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.14.4/firebase-database.js"></script>
    <script src="/js/app.js"></script>
    <script src="/js/authentication.js"></script>
    
</body>

</html>

我不知道为什么会这样!