0

I am currently using Firebase for email and password Authentication. My problem is how do I create the same UID for the 'Email and password authentication section' and the 'Database' section. They appear to have two separate UID. On a note, I used push() for the database section to save the data. For the email and password I used the simple devdoc createemailandpassword function.

This is the Authentication section UID

This is the Database section UID

2 Answers 2

1

After using createUserWithEmailAndPassword method, you will authenticate the user and, the user will have an unique id for him.

The push() generates a random id in the database.

You need to get the userid and then add it to the database:

var user = firebase.auth().currentUser;
var uid,useremail;
if (user != null) {
uid = user.uid;
useremail = user.email;
var database = firebase.database();
database.ref().child("users").child(uid).set({
email:useremail
  });
}

more info here:

https://firebase.google.com/docs/auth/web/manage-users

https://firebase.google.com/docs/database/web/read-and-write

Sign up to request clarification or add additional context in comments.

Comments

1

The UID in the Auth panel is generated by Firebase after authentication, when you get this in the callback, save a "user" dictionary under that UID, under a "Users" node. I'm not sure what coding language you're using but in iOS (swift) it would look something like this. (It may not be perfect but you should get the idea).

Auth.auth().signIn(with: credential) { (user, error) in
     //Check that there's no error and grab the user.uid property and call the below function after creating a user dictionary
})

func registerNewUserInDatabase(dictionary: Dictionary<String, Any>, uid: String) {
    userRef.child(uid).updateChildValues(dictionary)
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.