React-moralis find user given an objectId

Hi, how’s it possible that const { data } = useMoralisQuery(“User”) doesnt find any object? I have 3 users in my DB and the query works perfectly with other objects

I don’t expect for that query to return all users from db when executed in front end. You can get all the users with a cloud function with useMasterKey parameter.
But I don’t know why you don’t get current logged in user with current code.

I do get current logged user with const { user } = useMoralis() but I need to get the info of another user using his key like this:
const { data : userProfile } = useMoralisQuery("User", query => query .equalTo("objectId", props.uid) )

you can use a cloud function to get any user info, something similar to this:

Moralis.Cloud.define("getUsers", async function (request) {
  const query = new Parse.Query("User");
  const result = await query.find({ useMasterKey: true });
  return result;

a cloud function can use useMasterKey parameter to get all users info

Thank you! So the only way to get an user is using the Master Key?

You have to access User table from the backend (cloud function) with master key as it has sensitive user data and Moralis doesnt allow all clients to get info about all Users from the SDK

1 Like

Ohh so that’s why… Thank you!!

1 Like