【发布时间】:2018-03-10 19:02:37
【问题描述】:
我正在使用 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
【问题讨论】:
标签: firebase react-native firebase-authentication