【问题标题】:React Native + Firebase Auth - displayNameReact Native + Firebase 身份验证 - displayName
【发布时间】: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


    【解决方案1】:

    如果您想支持使用用户名/密码登录:

    在注册时,您可以询问用户名、电子邮件和密码。 您使用 createUserWithEmailAndPassword 创建帐户,然后在 Firebase 数据库中保存用户名到电子邮件的映射,同时确保用户名的唯一性。

    下次用户使用用户名和密码登录时,您可以从用户名获取电子邮件,然后使用提供的电子邮件和密码signInWithEmailAndPassword

    【讨论】:

    • 您好,谢谢您的回答!在登录屏幕中,用户将使用电子邮件和密码输入帐户,在注册屏幕中,用户将使用名称、电子邮件和密码创建帐户。我想问注册表中的用户名在一个屏幕上返回用户信息,会有用户名和邮箱等用户账户信息显示出来。
    • 很抱歉,我不明白您的用例。
    • 基本上我想使用 Firebase 身份验证创建一个具有用户名、电子邮件和密码的用户。但没问题。还是谢谢你!
    猜你喜欢
    • 1970-01-01
    • 2017-07-12
    • 2016-12-25
    • 2017-06-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 2021-10-31
    • 2020-10-04
    相关资源
    最近更新 更多