Xx-CODE-xX
Xx-CODE-xX

Reputation: 1

React Native + Firebase Auth - displayName

I'm working on a registry screen inside an application made with React Native. I am using Firebase authentication to create a new user.

On the login screen, I'm using .signInWithEmailAndPassword (to access an account), and on the registration screen I'm using .createUserWithEmailAndPassword (to create a user), and reading articles about Firebase authentication, I know I can use displayName to receive the name user, and photoUrl to receive a photo of the user.

What I would like to do is create a new user using the username, email and password. Even reading articles on the subject, I don't know a way to do this.

THIS IS MY CODE:

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}]);
  });
}

Basically I want to create a new user with the user name, email and password using the Firebase Authentication.

Can any of you guys give me an example of how I can create a user with username, email, and password?

If you want to see what I'm trying to do, I created a project to improve my knowledge in React Native? https://github.com/JoaoVRodrigues01/React-Native-Codec-App

Upvotes: 0

Views: 1559

Answers (1)

bojeil
bojeil

Reputation: 30838

If you want to support sign in with username/password:

On sign up you can ask for username, email and password. You create the account with createUserWithEmailAndPassword and then save a mapping of username to email in the Firebase Database while ensuring uniqueness of username.

The next time a user signs in with username and password, you can get the email from the username and then signInWithEmailAndPassword using that email and password provided.

Upvotes: 1

Related Questions