我正在尝试使用Firebase创建输入系统,但无法读取输入到输入中的值。顺便说一句,当我尝试结果成功时,Firebase会在控制台上运行。
但是似乎出了点问题,我也不知道你在哪里。例如,我从某个地方下载了它,而在那儿工作时却无法在这里工作。
我需要帮助的人谢谢
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
const user = firebase.auth().currentUser;
if(user != null){
const email_id = user.email;
console.log("Welcome User: " + email_id)
}
} else {
console.log("No one here.");
}
});
function userlogin(){
const user_email = document.getElementById("user_email").valueOf();
const user_pass = document.getElementById("user_pass").valueOf();
firebase.auth().signInWithEmailAndPassword(user_email, user_pass).catch(function(error) {
// Handle Errors here.
const errorMessage = error.message;
window.alert("Error : " + errorMessage);
});
}
<div class="container" style="margin-top:10%;">
<div class="row main-div" id="login_area">
<div class="col-md-5">
<h3 class="text-center">Chairboard Login</h3><br><br>
<form role="form">
<div class="form-group">
<input placeholder="E-Mail Address" type="email" class="form-control" id="chair_email" />
</div>
<div class="form-group">
<input placeholder="Password" type="password" class="form-control" id="chair_pass" />
</div>
<button type="submit" class="btn btn-primary" onclick="chairLogin()">Login to Account</button>
</form>
</div>
<div class="col-md-2" style="margin-top: 5%; margin-bottom: 5%;"></div>
<div class="col-md-5">
<h3 class="text-center">Delegate Login</h3><br><br>
<form role="form">
<div class="form-group">
<input placeholder="E-Mail Address" type="email" class="form-control" id="user_email"/>
</div>
<div class="form-group">
<input placeholder="Password" type="password" class="form-control" id="user_pass"/>
</div>
<button type="submit" class="btn btn-primary" onclick="userlogin()">Login to Account</button>
</form>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<script src="https://www.gstatic.com/firebasejs/5.9.0/firebase.js"></script>
<script>
// Initialize Firebase
const config = {
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx"
};
firebase.initializeApp(config);
console.log("Firebase Loaded");
</script>
<script src="app/sign.js"></script>
答案 0 :(得分:1)
您需要电子邮件和密码的值,所以
const user_email = document.getElementById("user_email").valueOf();
const user_pass = document.getElementById("user_pass").valueOf();
应该成为
const user_email = document.getElementById("user_email").value;
const user_pass = document.getElementById("user_pass").value;