I would do a search form using keywords, I can do it with more ancient versions of @angular/fire but not with this one.
Always the same error :
FirebaseError : missing or insufficient permissions
I've tried to implement a collectionGroup new function inside my Angular app but it shows the error above.
Then I've tried to create a firebase function to return my collectionGroup but I can't re-use the object because it's not @angular/fire, it's purely firebase, right ?
Inside my component :
import {
collectionData,
collectionGroup,
DocumentData,
Firestore,
query,
where,
} from '@angular/fire/firestore';
search() {
if (this.searchForm.value.search.length) {
let substances = collectionGroup(this.afStore, 'substance');
// ERROR FirebaseError: Missing or insufficient permissions.
let query$ = query(
substances,
where('keywordsName', 'array-contains', this.searchForm.value.search)
);
let res = collectionData(query$);
let res$ = res.pipe(
map((families: DocumentData[]) => {
families.forEach((family: DocumentData) => {
family['color'] = this.riskReduction.generateRandomColor();
});
return families;
})
);
this.riskReduction.setSubstances(res$);
} else {
this.riskReduction.setSubstances(this.riskReduction.getSubstances());
}
}
Edit : Else I tried with the function :
/**
* ANCHOR: Search a substance
*/
export const searchSubstance = functions.https.onCall(async (data, context) => {
try {
const ref = admin.firestore().collectionGroup('substance');
return <BasicResponse>{
status: 'success',
data: { substances: ref.get() },
};
} catch (e) {
console.log(e);
return <BasicResponse>{ status: 'error', message: e };
}
});
thanks for your help