3

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?

M. Alves
  • 35
  • 1
  • 6
  • 1
    First, it is important to notice that Parse Server has a built-in forgot password feature (https://docs.parseplatform.org/js/guide/#resetting-passwords). Anyway, if you want to build your custom made one, you can create a cloud code function and then call this cloud code function with `Parse.Cloud.run('theNameOfTheFunction', { user: yourUserVarGoesHere })`. – Davi Macêdo Sep 17 '19 at 05:20
  • Thanks, i knew about the forgot password feature... After i create this function on cloud, how can i access it in the app? – M. Alves Sep 17 '19 at 12:56
  • 1
    The code that I sent you is actually the one that you will use in the app in order to call the function. – Davi Macêdo Sep 17 '19 at 15:01
  • Ok got it, in "theNameOfTheFunction", i got to create one in the api code Cloud/Main.js ? Right? – M. Alves Sep 17 '19 at 19:30
  • 1
    Yes. I've just added an answer so it can be more clear. – Davi Macêdo Sep 17 '19 at 19:36

1 Answers1

2

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() });
Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11
  • Thanks for you help, i'm going to test this code, and give you a feedback. – M. Alves Sep 17 '19 at 20:37
  • I'm getting this error "ReferenceError: Parse is not defined" When i save a new object, the function Parse.Cloud.afterSave("MyClass" {...}) to manipulate the params... I tried to use var Parse = require('parse'), but it didn't work. – M. Alves Sep 24 '19 at 18:39
  • I fixed this, but i have another question... I'm passing the email to the Cloud Code. how this function "ParseUser.RequestPasswordResetAsync("email@example.com");" should work? i'm passing the email but its says that i don't have a template for that. I thought that it would send an email to a default Parse Page. – M. Alves Sep 27 '19 at 17:26
  • Can you please open a new question sharing your current code, the error message and the configuration that you are using to initialize Parse? – Davi Macêdo Sep 27 '19 at 21:26