Web Google authentication with firebase

2019-01-20 02:52发布

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.

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条回答
做自己的国王
2楼-- · 2019-01-20 03:18

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.

Recently even i faced the same error.

You are opening this file directly in the browser without any webserver. Firebase authentication work if you open file directly. Try to load your html through webserver it should solve your issue. The reason behind this bug is when you use authentication services they will use web storage. web storage not works when you open a html file directly without any web browser

For example use use apache and open through apache like http://localhost/filename.html in browser

查看更多
姐就是有狂的资本
3楼-- · 2019-01-20 03:34

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);
    });
查看更多
登录 后发表回答