I am in the process of building a web application using Vue.js + Firebase. Currently, I am working on implementing a sign-up feature for the project.
The sign-up feature utilizes a Firebase auth function and it is functioning correctly. However, I also need to create a document in the Firestore 'users' collection where the document ID should be the same as the auth UID. Unfortunately, this part is not working as expected and I require some assistance.
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)
})
}
}
Temporary Firestore security rules are set as follows:
match /{document=**} {
allow read, write, create: if request.auth.uid != null;
}