Closed timofeysie closed 3 years ago
This is using the firebase realtime database for we. The solution was to check if the user object exists first.
firebase.auth().onAuthStateChanged(user => {
if (user) {
const database = firebase.database();
this.userId = firebase.auth().currentUser.uid;
}
});
Not sure if this is the final solution, but will reopen this if needed.
What seemed to work for this, was returning the userId from the setup function, rather than doing the two as separate calls.
const userId = this.setupFirebase();
...
setupFirebase() {
const firebaseConfig = {
apiKey: 'xxx',
...
};
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
firebase.auth().onAuthStateChanged(user => {
if (user) {
const database = firebase.database();
}
return firebase.auth().currentUser.uid;
});
}
It seems pretty weak, but has appeared to solve the problem when used like this.
at RealtimeDbService.push../src/app/core/firebase/realtime-db.service.ts.RealtimeDbService.setupFirebase (realtime-db.service.ts:147)