使用Firebase创建用户数据库
我正在使用firebase对用户进行身份验证。 我想添加一个要添加到数据库的用户(在他注册应用程序之后)。 用户正在使用以下内容注册应用程序:使用Firebase创建用户数据库,firebase,react-native,Firebase,React Native,我正在使用firebase对用户进行身份验证。 我想添加一个要添加到数据库的用户(在他注册应用程序之后)。 用户正在使用以下内容注册应用程序: firebaseRef.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then(function(newUser){ //good this.setState({ status: 'ok' }); }).
firebaseRef.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then(function(newUser){
//good
this.setState({
status: 'ok'
});
}).catch(function(error){
//bad
});
在此代码之后,用户确实会出现在Firebase控制台的“身份验证”部分
我还想把它添加到数据库中
在这个数据库中,我想要一个用户列表。每个用户应该有几个属性,如姓名、电子邮件和朋友列表(其他用户)
我正在寻找如何做到这一点,但我仍然没有一个线索。
如果你们能给我信息来源/例子,我将不胜感激
提前谢谢 标准做法是在Firebase中有一个/users节点 创建用户后,将为其分配一个用户id(uid),该id可以在填充create函数的闭包中获得 在您的用户节点中,您可以使用用户的uid作为密钥创建一个节点,然后创建要存储的关于用户的任何其他数据
users
uid_0
nickname: "Michael"
uid_1
nickname: "Jermaine"
要写作,就要这样做
firebaseRef.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then(function(authData){
this.writeUserData(authData.uid, users_nickname);
}).catch(function(error){
//bad
});
writeUserData(the_uid, the_nickname) {
// the_uid can also come from let userId = firebaseApp.auth().currentUser.uid;
firebase.database().ref('users/' + the_uid + '/').set({
nickname: the_nickname,
});
}
这将向Firebase添加以下内容
users
uid_x
nickname: "some nickname"
(在我的iPad上没有经过测试,但你知道了)谢谢:),我怎么能做到?你能提供什么信息来源吗?