I managed to make an authentication functionality, where the user can use:
- sign up
- log in
- update / delete account
- sign out
Everything works good until I sign out. I use onSnapshot() for the update functionality
So everytime the auth state changes i set the returned data in the component's state.
firebase_auth.auth().onAuthStateChanged(user => {
if(user) {
firebase.collection('users').doc(user.uid).onSnapshot(doc => {
doc.exists && this.setState(prevState => ({ ...prevState, user_data: doc.data() }));
});
} else this.setState(prevState => ({ ...prevState, user_data: null }));
});
signOut() {
firebase.auth().signOut();
}
When i sign out the following error occurs:
Uncaught Error in onSnapshot: FirebaseError: Missing or insufficient permissions.
Here are my database rules. I use firebase cloud storage.
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid} {
allow read, write: if request.auth.uid == uid
}
}
}
And if i stop the onSnapshot listener, not even the log in will work.
firebase_auth.auth().onAuthStateChanged(user => {
if(user) {
const unsubscribe = firebase.collection('users').doc(user.uid).onSnapshot(doc => {
doc.exists && this.setState(prevState => ({ ...prevState, user_data: doc.data() }));
});
unsubscribe();
} else this.setState(prevState => ({ ...prevState, user_data: null }));
});