这是我的firebase里面的javascript函数:
function submitToDatabase(){
var email = document.getElementById('username').value;
var password = document.getElementById('password').value;
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error){
console.log('i am erroring')
var errorCode = error.code;
var errorMessage = error.message;
})
};
这是我从我的代码中调用此函数的地方:
username:<br>
<input id="username" type="text" name="username" ><br>
password:<br>
<input id="password" type="text" name="password" ><br><br>
<input type="submit" onclick=submitToDatabase() value="Submit">
我可以验证该函数获取电子邮件和密码值,因为我有控制台。记录它们但它跳入函数的错误部分,我无法解决为什么? 如何在我的函数内部调用firebase.auth
答案 0 :(得分:0)
允许用户拥有显示名称(vs向世界展示他们的电子邮件)。试试这个:
function registerPasswordUser(email,displayName,password,photoURL){
var user = null;
//NULLIFY EMPTY ARGUMENTS
for (var i = 0; i < arguments.length; i++) {
arguments[i] = arguments[i] ? arguments[i] : null;
}
auth.createUserWithEmailAndPassword(email, password)
.then(function () {
user = auth.currentUser;
user.sendEmailVerification();
})
.then(function () {
user.updateProfile({
displayName: displayName,
photoURL: photoURL
});
})
.catch(function(error) {
toast(error.message,7000);
});
toast('Validation link was sent to ' + email + '.', 7000);
registerCard.style.display = "none";
}