使用firebase进行Web身份验证

问题描述 投票:5回答:3

未捕获的异常:错误:此应用程序运行的环境不支持此操作。 “location.protocol”必须是http,https或chrome-extension,并且必须启用网络存储。

var config = {
apiKey: "*****",
authDomain: "******",
};
firebase.initializeApp(config);
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('https://www.googleapis.com/auth/drive');
firebase.auth().signInWithRedirect(provider);
alert(1);
}
javascript firebase google-drive-sdk firebase-authentication adobe-indesign
3个回答
5
投票

未捕获的异常:错误:此应用程序运行的环境不支持此操作。 “location.protocol”必须是HTTP,HTTPS或chrome-extension,并且必须启用网络存储。

最近我甚至面临同样的错误。

您正在浏览器中直接打开此文件,而不使用任何Web服务器。如果直接打开文件,Firebase身份验证将不起作用。尝试通过Web服务器加载HTML,它应该解决您的问题。这个错误背后的原因是当您使用身份验证服务时,他们将使用Web存储。在没有任何Web浏览器的情况下直接打开HTML文件时,Web存储不起作用

例如,在浏览器中使用apache并通过像http://localhost/filename.html这样的apache打开


0
投票

试试这个代码。它应该工作。

    var config = {
    apiKey: "*****",
    authDomain: "******",
    };
    firebase.initializeApp(config);
    var provider = new firebase.auth.GoogleAuthProvider();
    provider.addScope('profile');
    provider.addScope('https://www.googleapis.com/auth/drive');
    firebase.auth().signInWithRedirect(provider);
    //add the code below to your previous lines
    firebase.auth().getRedirectResult().then(function(authData) {
        console.log(authData);
    }).catch(function(error) {
        console.log(error);
    });

-1
投票

最简单的方法....只需在github上传你的文件并使用github页面运行(即.https://ur name.github.io/yr dir / yr html文件。

© www.soinside.com 2019 - 2024. All rights reserved.