4

I have created a CloudCode function that looks up the users ObjectId based off of their Username.

the result I receive are

Ran cloud function findUserByEmail with: Input: {"email":"[email protected]"} Result: undefined

this is my JavaScript for the CloudCode

------------------------------------SOLUTION-----------------------------------------

Parse.Cloud.define("findUserByEmail", function(request, response){
   var email = request.params.email;

   if(!email) {
   response.error("Missing parameter: email");
   return ;
   }

   Parse.Cloud.useMasterKey();

   var query = new Parse.Query(Parse.User);

   query.equalTo("username", email);
   query.**first**({
   success: function(user){
       var objectId = user.id;

   response.success(objectId);
   },

   error: function(error) {
       console.error(error);
       response.error("An error occured while lookup the users objectid");
   }

   });

 });

Not sure why my Results "Undefined"

1 Answer 1

4

query.find() returns an array of results, so user.id would definitely be undefined.

I'd prefer query.first() which returns just one.

This should work if you just change find to first.

Sign up to request clarification or add additional context in comments.

4 Comments

you're my hero. Thank you for all your help today.
or just user[0].id will also work, but better rename those variables to make sense :-)
Which variable name doesn't make sense? (I know username is being checked but the username can only be an email address)
'user' if using 'find' which returns an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.