I am trying to fetch a list of users from my firestore database, and determine if the logged in user is an admin (i.e. he's in the list).
This is my code:
isAdmin(user: any): boolean {
var col = this.afs.collection('admins');
var docRef = col.doc('mini-admins');
docRef.ref.get().then(function (doc) {
if (doc.data().user == user)
return true;
}).catch(function (error) {
console.log("Error getting document:", error);
});
return false;
}
However, even though the user is an admin, the function doesn't work. It looks like it isn't waiting for it to finish before proceeding.
How do I fix this?