Query is not wotking(Solved)

Hi, Im having a problem with wix query.

I have a site that sells paid language lessons and Im trying to set that when a user clicks on a lesson Image there a query that checks if the user email exists in the paid member collection. if it does exist he needs to be redirected to the lesson page, if not theres a lightbox that says he needs to pay first.
There seems to be no problems with my code, but still it doesn’t work :frowning:
Im inserting few email addresses to the paid member collection,just for example, and then trying to login with one of them as a site member. But even that the email Im using do exists in the live collection Im not being redirected to the lesson and I get only the lightbox says I need to pay.
this is the code Im using:


I would really appreciate any help, Thanks !

Hi,

I noticed that you searched userEmail without setting its value:


Moreover, I noticed that you haven’t used the query function properly. I recommend also reading the MDN Promise documentation.

Have a good day,
Tal.

Hi, thanks for your replay.
I read the documentation but I got lost a little bit. can you explain how should I add a value to the userEmail? cause i tried also doing it with the getEmail() but it didnt work.
And also, what do you mean by not using the query function properly? what am I doing wrong?

Thanks.

Hi,

You can find an example of how to get a user’s email here .
Moreover, I recommend reading the following articles:

As for your second query, you’ve forgot to add the " then " part of the promise when calling the " query " function ( the second green square I highlighted ):

wixData.query("myCollection")
    .find() 
    .then( (results) => { 
        let firstItem = results.items[0]; 
    } ) 
    .catch( (err) => { 
        let errorMsg = err;
    } );

Have a good day,
Tal.

Hi, Thanks again for your help.
So I walked through all the articles you posted and read everything, then I decided to try and do the query using the users Id instead of users Email, just to see if it works, and it did work.

The thing is that when Im trying to do this using the users Email it just doesn’t wotk.

Thats what get when Im trying to debug this problem:

Thanks!

Hey,

Javascript is an asynchronous language. Please note that the getEmail function returns a Promise . A promise is a proxy for a value not necessarily known when the promise is created. It allows you to associate handlers with an asynchronous action’s eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods : instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.

Therefore, you should use it as demonstrated on the getEmail documentation :

Good luck,
Tal.

Hi, thanks for the kind answer. I know that I have to use it with a promise and I did try to write the full promise but then it tells me that the user Email in the .eq field is undefined, so I just tried to do that without the promise which as your’e saying won’t wotk at all.