angularfire: Permission denied on all subsriptions after login and page refresh
Version info Angular: 12
Firebase: 8.6.1
AngularFire: 6.1.4
Other (e.g. Ionic/Cordova, Node, browser, operating system): MacOS Big Sur
How to reproduce these conditions
I’ve just updated project dependencies, both angular fire, firebase and angular and noticed, that user loses permission to make firebase requests.
When user logs in, everything works fine, but after he refreshes the page, he receives next error on all firebase subscriptions:
Error: permission_denied at /settings/PERSONAL_OFFER_ACTIVATION_MINUTES: Client doesn't have permission to access the desired data.
Here’s example of my service with login and some requests:
import firebase from 'firebase/app';
import { AngularFireDatabase } from '@angular/fire/database';
import { AngularFireAuth } from '@angular/fire/auth';
constructor(
private db: AngularFireDatabase,
public afAuth: AngularFireAuth
) { }
login(firebaseToken: string) {
return this.afAuth.signInWithCustomToken(firebaseToken);
}
async loginFb() {
const provider = new firebase.auth.FacebookAuthProvider();
const result = await this.afAuth.signInWithPopup(provider);
return result;
}
async loginGoogle() {
const provider = new firebase.auth.GoogleAuthProvider();
const result = await this.afAuth.signInWithPopup(provider);
return result;
}
getPersonalOfferTimer(): Observable<number> {
return this.db.object(`settings/PERSONAL_OFFER_ACTIVATION_MINUTES`).valueChanges() as Observable<number>;
}
getMovementsPurchaseTimeout(): Observable<number> {
return this.db.object(`settings/PURCHASE_MOVEMENTS_TIMEOUT`).valueChanges() as Observable<number>;
}
Will appreciate any help.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 15
The firebase emulators in recent versions are checking the server-deployed firebase access rules rather than your local rule definitions in the emulator. So you need to update your rules on the firebase server to gain access to the emulator data…this I suppose helps when you have entered rules on the firebase console by hand but are using emulators to serve the data itself.