Dev - Get class Data from my current user

Hello, how can i get data (only from my connected user) from my server with Query ?
Do I have to pass session token or something ?

For now, i get my data like this :
const GameScore = Moralis.Object.extend(“GameScore”);
const query = new Moralis.Query(GameScore);
query.equalTo(“client”, this.token);
const results = await query.find();

And i find only the data concerning by user by passing his ethAdress. I need to add it in my row.

Is there a better solution ?

Thanks for advance and have a good day

I don’t see the part where you pass user ethAddress in that code example.
Using ACLs may be a solution:
Without ACL you could get all the table data in a query if you don’t filter it, you will still be able to get all the table data from a cloud function using the master key.

The line “query.equalTo(“client”, this.token);”, this.token is the ethAdress.
With ACL, it will only get the data from my current user ?

For now when creating an objet, i add a column to refer to my user
const GameScore = Moralis.Object.extend(“GameScore”);
let gameScore = new GameScore();
gameScore.set(“money”, 5665);
gameScore.set(“client”, this.token);;

As you write, i use ACL and i find the solution to my problem. And i add a security to my application !

Thanks :slight_smile:

1 Like

I think that you could set the ACL in a way that the query will only return the data for current user, this is how it works now if you want to get the list of all the users with a query, you’ll get only the information about current user. But there are also cases when you will want to add a column to specify the user that created that entry, I think that it is something related to pointers on how it can be done to have a column that it is a pointer to a user object.

Yes exacly. Thanks man for the explanation. I just try ACL and it works great.
Have a good day !