我正在用React Native制作的应用程序中处理注册表屏幕。我正在使用Firebase身份验证来创建新用户。
在登录屏幕上,我使用.signInWithEmailAndPassword (访问帐户),在注册屏幕上,我使用.createUserWithEmailAndPassword (创建用户),在阅读有关Firebase身份验证的文章时,我知道我可以使用displayName接收用户名,使用photoUrl接收用户的照片。
我想做的是创建一个新的用户使用用户名,电子邮件和密码。即使阅读关于这个主题的文章,我也不知道有什么方法可以做到这一点。
这是我的代码:
signup() {
this.setState({
// When waiting for the firebase server show the loading indicator.
loading: true
});
// Make a call to firebase to create a new user.
this.props.firebaseApp.auth().createUserWithEmailAndPassword(this.state.email, this.state.password).then((userData) => {
// then and catch are methods that we call on the Promise returned from
// createUserWithEmailAndPassword
Alert.alert('Success', 'Congrats!', [{text: 'OK!', onPress: this.dismiss}]);
this.setState({
// Clear out the fields when the user logs in and hide the progress indicator.
email: '',
password: '',
loading: false
});
AsyncStorage.setItem('userData', JSON.stringify(userData));
this.props.navigator.push({
component: Account
});
}).catch((error) => {
// Leave the fields filled when an error occurs and hide the progress indicator.
this.setState({
loading: false
});
Alert.alert('Ops', 'Error: ' + error.message, [{text: 'OK!', onPress: this.dismiss}]);
});
}基本上,我想使用Firebase身份验证创建一个具有用户名、电子邮件和密码的新用户。
你们谁能给我举个例子,告诉我如何使用用户名、电子邮件和密码创建用户?
如果你想知道我在做什么,我创建了一个项目来提高我在React Native?https://github.com/JoaoVRodrigues01/React-Native-Codec-App中的知识
发布于 2017-09-29 08:15:56
如果您想支持使用用户名/密码登录:
在注册时,您可以要求用户名,电子邮件和密码。您可以使用createUserWithEmailAndPassword创建帐户,然后在Firebase数据库中保存用户名到电子邮件的映射,同时确保用户名的唯一性。
下次用户使用用户名和密码登录时,您可以从用户名获取电子邮件,然后使用提供的电子邮件和密码进行signInWithEmailAndPassword。
https://stackoverflow.com/questions/46479245
复制相似问题