all.
I'm developing a web app using Vue.js + Firebase. In the project, I'm developing a sign-up feature.
That feature basically uses an firebase auth function and it works correctly. As an additional feature, I need to create a document in the Firestore 'users' collection. Here, the document ID is shall be same as the auth UID. But that doesn't work as intended. I just need some help.
const firebaseApp = firebase.initializeApp(firebase_config)
const db = firebaseApp.firestore();
const auth = firebaseApp.auth();
export {db, auth};
import {db,auth} from '../plugins/firebase'
// ( omit ) //
methods: {
// this works
test: function(){
db.collection("users").doc("new_user").set({
displayName: "Bob",
}).catch(error=>{
console.log('error on debugging: ',error)
})
},
register: function(){
auth.createUserWithEmailAndPassword(this.user_mail, this.user_password)
.then(result=>{
// this works
console.log(result.user.uid)
// this does not work
db.collection('users').doc(result.user.uid).set({
displayName: 'John',
}).catch(error=>{
console.log('fail to add data: ',error)
})
})
.catch(error=>{
console.log('something goes wrong on auth: ',error)
})
}
}
Firestore security rules are temporally as below.
match /{document=**} {
allow read, write, create: if request.auth.uid != null;
}
firebaseApp? You define the Firebase Auth service withfirebase.auth()and you define the Firestore service withfirebaseApp.firestore(). You should most probably dofirebase.firestore()sincefirebase.auth()seem to work. - Renaud Tarnec