I want to make an app with angular and Firebase. I want to restrict read and write access for my database for one user. Therefore i made this rule.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if "auth.uid === 'gzL3tHnx6JQexMuK4h2Nyo0thHS2'"
}
}
}
This cause as expected an permission denied error.
The Framework makes it really simple to write and get data from the database, register users and make a login. Unfortunately the framework does not use HTTP Interceptors to append cred. to the request. Can somehow combine AngularFirestore and AngularFire Auth Methods. Example implementations below:
export class AppComponent {
private shirtCollection: AngularFirestoreCollection<Shirt>;
shirts: Observable<ShirtId[]>;
constructor(private readonly afs: AngularFirestore) {
this.shirtCollection = afs.collection<Shirt>('shirts');
// .snapshotChanges() returns a DocumentChangeAction[], which contains
// a lot of information about "what happened" with each change. If you want to
// get the data and the id use the map operator.
this.shirts = this.shirtCollection.snapshotChanges().pipe(
map(actions => actions.map(a => {
const data = a.payload.doc.data() as Shirt;
const id = a.payload.doc.id;
return { id, ...data };
}))
);
}
private socialSignIn(provider: number): firebase.Promise<FirebaseAuthState> {
return this.af.auth.login({AuthProviders.Github, method: AuthMethods.Popup})
.then(() => this.updateUserData() )
.catch(error => console.log(error));
}
}