简体   繁体   English

使用Firebase进行Web Google身份验证

[英]Web Google authentication with firebase

uncaught exception: Error: This operation is not supported in the environment this application is running on. 未捕获的异常:错误:在运行此应用程序的环境中不支持此操作。 "location.protocol" must be http, https or chrome-extension and web storage must be enabled. “ 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);
}

uncaught exception: Error: This operation is not supported in the environment this application is running on. 未捕获的异常:错误:在运行此应用程序的环境中不支持此操作。 "location.protocol" must be HTTP, HTTPS or chrome-extension and web storage must be enabled. “ location.protocol”必须为HTTP,HTTPS或chrome-extension,并且必须启用网络存储。

Recently even i faced the same error. 最近,即使我也遇到了同样的错误。

You are opening this file directly in the browser without any web server. 您无需任何Web服务器即可直接在浏览器中打开此文件。 Firebase authentication won't work if you open the file directly. 如果您直接打开文件,则Firebase身份验证将不起作用。 Try to load your HTML through web server it should solve your issue. 尝试通过Web服务器加载HTML,它应该可以解决您的问题。 The reason behind this bug is when you use authentication services they will use web storage. 出现此错误的原因是,当您使用身份验证服务时,它们将使用Web存储。 web storage does not work when you open an HTML file directly without any web browser 在没有任何Web浏览器的情况下直接打开HTML文件时,Web存储不起作用

For example, use apache and open through apache like http://localhost/filename.html in the browser 例如,使用apache并在浏览器中通过apache(例如http://localhost/filename.html)打开

Try this code. 试试这个代码。 It should work. 它应该工作。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM