首页 文章

使用firebase进行Web身份验证

提问于
浏览
2

uncaught exception:错误:运行此应用程序的环境不支持此操作 . “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);
}

2 回答

  • 3

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

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

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

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

  • 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);
        });
    

相关问题