Hey! So I’ve tried to do a couple things: (1.) to get the total users in the db, and the (2.) to try to return a API Key (that would only show client side if {user === true}
Cloud Code
// Get total users
Moralis.Cloud.define("get_nr_users", async (request) => {
query = new Moralis.Query("User");
x = await query.count({useMasterKey : true});
return x;
});
// Get Company API Key
Moralis.Cloud.define("get_company_api_key", async (request) => {
x = '_APIKEYGOESHERE_';
return x;
});
Client-side
In the front-end, I called the # of users function this way:
// state variable
const [numOfUsers, setNumOfUsers] = useState('');
// function
Moralis.Cloud.run('get_nr_users').then(res=> {
// JSON.stringify turns response into string
const users = JSON.stringify(res)
console.log(users)
setNumOfUsers(users)
}).catch(err=> console.log(err))
...
return (
{numOfUsers}
)
However, I get this error:
Error: You need to call Moralis.start with an applicationId before using Moralis.
Do you know what I might be doing wrong to call the cloud function? The cloud-functions don’t return any errors in the Moralis server.