[英]How to set user data after createUserWithEmailAndPassword (web)
I have search on other questions but I can't find anything, so I'm sorry if this is a duplicated. 我已经搜索了其他问题,但我找不到任何东西,所以如果这是重复的话,我很抱歉。
I'm trying to save extra user data on sign up to database, the signup is not a problem but I can't store the data, I'm trying this: 我正在尝试在注册到数据库时保存额外的用户数据,注册不是问题,但我无法存储数据,我正在尝试这样做:
//add a real time listener
firebase.auth().onAuthStateChanged(firebaseUser =>{
if (user != null) {
firebase.database().ref().child( firebaseUser.uid ).set( {
/**store data**/
} );
console.log("Sign-in provider: "+ firebaseUser.providerId);
console.log("Provider-specific UID: "+ firebaseUser.uid);
console.log("name: "+firebaseUser.name);
console.log("email: "+firebaseUser.email);
console.log("country:"+firebaseUser.country);
//console.log(" Photo URL: "+firebaseUser.photoURL);
//window.location.href = "index.html";
}else{
console.log('not logged in');
}
});
You can store any of the properties of the Firebase User . 您可以存储Firebase用户的任何属性。 This should work: 这应该工作:
firebase.database().ref().child( firebaseUser.uid ).set( {
firebaseUser.displayName,
lastSignInTimestamp: Date.now()
});
If that doesn't work, your user might not have permission to write to the location in the database. 如果这不起作用,则您的用户可能没有权限写入数据库中的位置。 To troubleshoot that, attach an error listener: 要解决此问题,请附加错误侦听器:
firebase.database().ref().child( firebaseUser.uid ).set( {
firebaseUser.displayName,
lastSignInTimestamp: Date.now()
}.catch(function(error) {
console.error(error);
});
If indeed it's a security problem, see the first blue note in the Firebase documentation about writing data to the database . 如果确实存在安全问题,请参阅Firebase文档中有关将数据写入数据库的第一个蓝色注释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.