firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
console.log("Hurray ! signed in successfully !");
} else {
// No user is signed in.
console.log("Sign in required !");
$("#login-btn-nav").click();
}
});
$("#login-btn").on('click',function(){
console.log("Hello");
var email = $("#email-input").val();
var password = $("#password-input").val();
if(email != "" && password != ""){
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// ...
window.alert("Following error encountered : "+errorMessage+" .");
});
}
});
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-messaging.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyDAvfWcdBTtmDbK7_aOkWFCRxNl1K4PDck",
authDomain: "sarahhah-8e315.firebaseapp.com",
databaseURL: "https://sarahhah-8e315.firebaseio.com",
projectId: "sarahhah-8e315",
storageBucket: "sarahhah-8e315.appspot.com",
messagingSenderId: "965679781332"
};
firebase.initializeApp(config);
console.log(config);
</script>
<script type="text/javascript" src="assets/js/login.js"></script>
发生了网络错误(例如超时,中断连接或无法访问的主机)。
在firebase的web集成中
提前感谢您的合作