I'm using reactjs and my database is firebase.
I'm trying to send an invite for a group. The variables that are being passed to the function are the group's id (groupID), the group's name (groupName) which isn't used for the check but is passed onto the inviting function, and the invitee's email address (invite). It checks if an invite already exists and if not it calls the invite code, if not it just sends an alert saying the user already has an invite. This is my code for checking:
await props.firestore
.collection("invites")
.where("groupID", "==", groupID)
.where("invitee", "==", invite)
.get()
.then(async (invitation) => {
if (invitation.exists) {
alert("User already has invite");
} else {
// Send Invite!
await props.firestore
.collection("invites")
.add({})
.then(async (ref) => {
SendInvite(invite,groupID,groupName);
alert("INVITE SENT");
});
}
});
The issue is its not actually grabbing anything and always sending an invite. This is how my database is set up:
There were 2 issues preventing it to work.
Firstly, the variable "invite" appeared to be a string and acted like a string however when compared to what was in the database it would return a false. Thus, I had to modify it to ""+invite
to cast it to a string. I'm unsure why it wasn't a string to begin with.
Secondly, instead of ".exist" it should be ".empty". These are the final changes:
.collection("invites")
.where("invitee", "==", "" + invite)
.where("groupID", "==", "" + groupID)
.get()
.then(async (inviteData) => {
if (inviteData.empty) {