[英]Web Google authentication with firebase
未捕获的异常:错误:在运行此应用程序的环境中不支持此操作。 “ 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);
}
未捕获的异常:错误:在运行此应用程序的环境中不支持此操作。 “ location.protocol”必须为HTTP,HTTPS或chrome-extension,并且必须启用网络存储。
最近,即使我也遇到了同样的错误。
您无需任何Web服务器即可直接在浏览器中打开此文件。 如果您直接打开文件,则Firebase身份验证将不起作用。 尝试通过Web服务器加载HTML,它应该可以解决您的问题。 出现此错误的原因是,当您使用身份验证服务时,它们将使用Web存储。 在没有任何Web浏览器的情况下直接打开HTML文件时,Web存储不起作用
例如,使用apache并在浏览器中通过apache(例如http://localhost/filename.html)打开
试试这个代码。 它应该工作。
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.