Reputation: 522
firebase is beating me like a mother with no mercy. Look at my code:
ref.createUser({
email : $("#email").val(),
password : $("#senha").val()
}, function(error, userData) {
if (error) {
alert("Nao foi possivel cadastrar: "+error);
} else {
ref.child("fornecedores").push({
[userData.uid]:{
email: $("#email").val(),
logo: nome+".jpg",
nome: $("#nome").val()
}
},function(error) {
if (error) {
alert("Nao foi possivel salvar: " + error);
} else {
alert("Seus dados foram salvos!: "+userData.uid);
}
});
}
});
Everything works fine, there is no error, but look at my json: *
{
"fornecedores" : {
"-K7XNT_UrCyuM4KLfptO" : {
"5b0beab0-d32a-4115-b346-25a8d3e1fffe" : {
"email" : "[email protected]",
"logo" : "J.jpg",
"nome" : "Jequiti Cosméticos 5"
}
},
}
*
Why there are two keys??? Where this "-K7X..." came from???
Upvotes: 1
Views: 857
Reputation: 35648
push() auto generates the key to the node and then userData.uid is the child with email, logo and nome as it's children.
From Firebase Saving Data:
Every time you call push() your database generates a unique ID, like
messages/users/<unique-user-id>/<username>
Upvotes: 1
Reputation: 522
It works as Jay said, thanks!!!
ref.createUser({
email : $("#email").val(),
password : $("#senha").val()
}, function(error, userData) {
if (error) {
$("#load").css("display","none");
alert("Nao foi possivel salvar: "+error);
} else {
ref.child("fornecedores").child(userData.uid).set({
email: $("#email").val(),
logo: nome+".jpg",
nome: $("#nome").val()
},function(error) {
$("#load").css("display","none");
if (error) {
alert("Nao foi possivel salvar: " + error);
} else {
alert("Seus dados foram salvos!: "+userData.uid);
}
});
}
});
Upvotes: 0