问题
I am trying to write a pure javascript web app with firebase login through google auth, when I setup the auth in javascript I get the 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.". I am not sure what do to.
Here is my code (I removed my id's and whatnot):
<script src="https://www.gstatic.com/firebasejs/4.1.3/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "MY KEY",
authDomain: "MY DOMAIN",
databaseURLMY URL",
projectId: "MY ID",
storageBucket: "MY BUCKET",
messagingSenderId: "MY ID"
};
firebase.initializeApp(config);
function login() {
function newLoginHappened(user) {
if (user) {
//User is signed in
app(user);
} else {
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);
}
}
firebase.auth().onAuthStateChanged(newLoginHappened);
}
function app() {
document.getElementById("clientName").innerHTML = user.displayName;
}
window.onload = login;
</script>
回答1:
It means that you cannot run the file by just double clicking the html fine and opening it in browser. You need to run the file through a server.
来源:https://stackoverflow.com/questions/45059919/javascript-and-firebase-error-this-operation-is-not-supported-in-the-environmen