I am using firebase authentication and angularfirestore in my app, and I came across a strange problem. I want to delete a user document in firestore after I delete the user in firebase auth as shown below, but the firestore portion doesnt work.
Edit 2: In the code, this.currentUser is not the same as angularFireAuth.auth.currentUser. It is a local variable I created separately.
return this.angularFireAuth.auth.currentUser.delete().then(() => {
this.angularFirestore.collection("userData").doc(this.currentUser.email).delete().then(() => {
this.currentUser = null;
this.currentUserSubject$.next(this.currentUser);
this.setAuthenticationDetails({authType: null, rememberMe: false});
this.storageService.setRememberedUser(null);
});
})
However, if I were delete the document from firestore first, and delete the user from firebase auth afterwards, it works.
return this.angularFirestore.collection("userData").doc(this.currentUser.email).delete().then(() => {
return this.angularFireAuth.auth.currentUser.delete().then(() => {
this.currentUser = null;
this.currentUserSubject$.next(this.currentUser);
this.setAuthenticationDetails({authType: null, rememberMe: false});
this.storageService.setRememberedUser(null);
});
})
Anyone knows why this is happening? They both return promises so i expected the behaviour to be the same.
Edit 1: added catch, but nothing's being printed
return this.angularFireAuth.auth.currentUser.delete().then(() => {
return this.angularFirestore.collection("userData").doc(this.currentUser.email).delete().then(() => {
this.currentUser = null;
this.currentUserSubject$.next(this.currentUser);
this.setAuthenticationDetails({authType: null, rememberMe: false});
this.storageService.setRememberedUser(null);
}, (error) => {
console.log(error);
});
}, (error) => {
console.log(error);
})
Edit 3: Security Rules
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}