Search code examples
javascriptparse-platformparse-server

How can I call a function using parse-server


I'm developing a JavaScript web app, and I'm trying to make a "forgot password" feature. I know how to make a function on the server-side, in the Cloud code with Parse function. But what I can't do is pass the object from my controller (in the front-end side). By the way, I'm using ember.js.

I've tried to save ("user.save()") the object (even without changing anything) and then calling Parse.Cloud.AfterSave("user",(request){..}), but I was getting a error. How can I pass an object to the Cloud code?


Solution

  • In your main.js file, in order to create a cloud code function:

    Parse.Cloud.define('resetPassword', async req => {
      console.log(`My user is: ${req.object.getUsername()}`);
      ...
    });
    

    In your client code, in order to call the cloud code function:

    await Parse.Cloud.run('hello', { user: Parse.User.current() });