Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 本地http服务器未连接到firebase用户_Html_Node.js_Firebase_Firebase Authentication_Simplehttpserver - Fatal编程技术网

Html 本地http服务器未连接到firebase用户

Html 本地http服务器未连接到firebase用户,html,node.js,firebase,firebase-authentication,simplehttpserver,Html,Node.js,Firebase,Firebase Authentication,Simplehttpserver,我正在使用VisualStudio代码编辑器和NodeJSHTTP服务器。我已经创建了一个简单的登录页面,并在firebase中创建了一个用户。但我无法使用用户名登录。我用HTML和bootstrap编写了网页代码 index.html <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstra

我正在使用VisualStudio代码编辑器和NodeJSHTTP服务器。我已经创建了一个简单的登录页面,并在
firebase
中创建了一个用户。但我无法使用用户名登录。我用HTML和bootstrap编写了网页代码

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="http://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/5.3.0/firebase.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 type="button" id="btn-login" 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>
app.js文件

var config = {
    apiKey: "AIzaSyBF2wl4WHBbLHg90M3lAk_dNKZ7SAo0iE8",
    authDomain: "wallpaper-app-b7c7b.firebaseapp.com",
    databaseURL: "https://wallpaper-app-b7c7b.firebaseio.com",
    projectId: "wallpaper-app-b7c7b",
    storageBucket: "wallpaper-app-b7c7b.appspot.com",
    messagingSenderId: "302819877773"
  };
  firebase.initializeApp(config);
firebase.auth.Auth.persistence.LOCAL;

$("#btn-login").click(function(){

    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);
    });
});
<!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="http://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/5.3.0/firebase.js"></script>
</head>
<body>
    <h1>This is the Admin Page</h1>
    <script src="js/app.js"></script>
    <script>
        firebase.auth().onAuthStateChanged(function(user){
            if(!user){
                window.location.href="index.html";
            }
        });
    </script>
</body>
</html>
admin.html

var config = {
    apiKey: "AIzaSyBF2wl4WHBbLHg90M3lAk_dNKZ7SAo0iE8",
    authDomain: "wallpaper-app-b7c7b.firebaseapp.com",
    databaseURL: "https://wallpaper-app-b7c7b.firebaseio.com",
    projectId: "wallpaper-app-b7c7b",
    storageBucket: "wallpaper-app-b7c7b.appspot.com",
    messagingSenderId: "302819877773"
  };
  firebase.initializeApp(config);
firebase.auth.Auth.persistence.LOCAL;

$("#btn-login").click(function(){

    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);
    });
});
<!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="http://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/5.3.0/firebase.js"></script>
</head>
<body>
    <h1>This is the Admin Page</h1>
    <script src="js/app.js"></script>
    <script>
        firebase.auth().onAuthStateChanged(function(user){
            if(!user){
                window.location.href="index.html";
            }
        });
    </script>
</body>
</html>

这是管理页面
firebase.auth().onAuthStateChanged(函数(用户){
如果(!用户){
window.location.href=“index.html”;
}
});

firebase.auth.auth.Persistence.LOCAL行导致错误,有两个问题

  • 默认值已经是
    LOCAL
    ,因此无需对其进行定义
  • 定义持久性的正确方法是
    firebase.auth().setPersistence(firebase.auth.auth.Persistence.LOCAL)

  • 您看到的确切错误消息是什么?我看到了任何错误消息…我只是无法登录到admin.html页面我在firebase中搜索了很多我是创建用户,在授权域部分我看到了本地主机域,但我使用的是本地主机:8080我试图访问我的域,但它显示了一些错误。。我还能做什么。请告诉我。未捕获类型错误:无法读取app.js:11上未定义的属性“LOCAL”。我在浏览器控制台中看到此错误。您不需要行
    firebase.auth.auth.Persistence.LOCAL
    ,因为默认值已经是
    LOCAL
    ,调用它的正确方法应该是
    firebase.auth().setPersistence>(firebase.auth.auth.Persistence.LOCAL)