Reputation: 191
I've returned a promise 'db' to access the collection. The collection doesn't exist yet because when I allow the user to signup Firebase should automatically create the collection. I then created a doc by passing in a id so when I save to that document it's going to create an autoid for that document.
I then set a property called email and then passed the email value to this. Now the document will have the same id as the users.
The problem is it isn't creating a new collection, any ideas?
function signup(){
var userEmail = document.getElementById("email_field").value;
var userPass = document.getElementById("password_field").value;
firebase.auth().createUserWithEmailAndPassword(userEmail, userPass)(cred => {
return db.collection('users').doc(cred.user.uid).set({
email: document.getElementById("email_field").value
}).then
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
window.alert("Error : " + errorMessage);
// ...
});
}
Here is what I set in Cloud Firebase Rules and allowed documents to be created:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
Upvotes: 0
Views: 460
Reputation: 345
If you are not able to see any errors when calling the set method, I'd suggest you to use the firebase authenticatio triggers (to keep some logic separated and not a lot of promises in your current implementation)in that way you can make reference to the user information with the parameter that is given at the trigger
PS: do you need that "then" at the db invocation? (as doug has mentioned on his comment)
Upvotes: 1