Hi, I’m following this tutorial, and was able to set up cloud function logs and IDE on visual studio.
However, I’m not sure why when I run a cloud function, it says that the user is undefined even though my client side app is able to run Moralis and find the user.
Here is my client side code
this.user = Moralis.User.current();
this.user.id = this.user.get('ethAddress');
this.newService = await Moralis.Cloud.run("getService", {user:this.user.id});
Here is my cloud function
Moralis.Cloud.define("getService", async (request) => {
const logger = Moralis.Cloud.getLogger();
const query = new Moralis.Query("PlayerService");
query.equalTo("user", request.params.user);
//query for moralis user, may need more complex checks, multiple ids eth, email, etc, correct?
let results = {};
let service = {};
results = await query.find();
//return the service object of that player
//new player
if (!results[0]) {
logger.info(`change these results = ${results[0]}`);
results = {
service: {
testProperty: false
},
user: request.params.user
}
const PlayerService = Moralis.Object.extend("PlayerService");
const playerService = new PlayerService();
playerService.set(results);
playerService.save();
service = results.service;
}
else {
service = results[0].get("service");
}
return service;
},{
requireUser: true
});
Here is the Moralis Log
Failed running cloud function getService for user **undefined** with:
Input: {"user":"0x07d9d8635bfcb19cc5d868df02a0af2addba31f5"}
Error: {"message":"Validation failed. Please login to continue.","code":142}
Why is user undefined here?
(Also after I can identify the user on the cloud function, how can I reference that data there? I don’t want people being able to pass other people’s eth addresses)