2

I am attempting to setup my own custom password reset for the Parse Server as at the time it doesn't have that functionality.

I have followed this tutorial on stack overflow --> How to set up a Parse Server Using Heroku

I've also read through this issue on Github --> Tips for implementing password reset?

Here is what I have been following as a guide that was said on the Github issue:

An express route or a cloud function to handle a password reset submission, which queries for a user matching the username/email. Generate a one-time random code and save it somewhere along with the user... Email the user, using some mail provider, with a link.

An express route to handle the link, which takes the random code provided and searches for the user, validates it, and then presents them with the ability to provide a new password... Use the master key to override the password and save the user.

I have managed to complete the first paragraph, emailing the user with a link. Now I am trying to setup an express route that handles the link, and queries for the user, however my parse query doesn't seem to be working at all and heroku keeps timing out.

Here is my code in my index.js (the default class that comes with the parse server) for setting up an express route that takes the user's name from the link and does a query that gets the user and then sends their username.

*Note I know getting a user's name and then querying isn't scalable it is merely for testing purposes only.

//Testing web routes
app.get('/route', function(req, res) {

  var query = new Parse.Query("_User");

  query.equalTo("name", req.param("id"));

  query.get({
      success: function(user) {
          res.status(200).send(user.get("username"));
      },
      error: function(error) {
          res.status(200).send("error");
      }
  });

});

This is the link I click through:

enter image description here

What then happens that I don't understand is the page keeps loading and then after about 30 seconds heroku times out and shows this error on the webpage:

enter image description here

Then when I check my logs on heroku:

enter image description here

I notice this error:

at=error code=H12 desc="Request timeout" method=GET path="/route?id=John%20Smith"

The part that I don't understand is that even if there was an error with my parse query it should just send "error" because of the error handler and this line of code : res.status(200).send("error");.

I also know that the web route itself is working because I've tried this code:

//Testing web routes
app.get('/route', function(req, res) {

   res.status(200).send("Hello world");

});

And the website receives the "Hello world" text.

What is causing the time out error and why isn't my query working at all?

Community
  • 1
  • 1
Josh
  • 745
  • 1
  • 7
  • 22
  • 1
    I have this exact issue. The reason the timeout occurs is because the query fails on Parse server. However, the actual error comes from heroku timeout, which is why the error is not passed back to the cloud code/promise. The issue is that this should probably be passed back. Did you ever get that progressed? – StuartM Mar 08 '17 at 14:39
  • @StuartM Yes, can't remember of the top of my head but the error involved an incorrectly written / coded function above it. I recommend commenting out your whole class and then slowly uncommenting and testing in increments to find the point where it works / doesn't. That's how I fixed it. – Josh Mar 09 '17 at 10:05
  • I'm assuming you are using MongoDb on mLab, go to your mLab database management page and look at the slow queries and generate indexes to speed up your queries. – Steve McMeen May 31 '17 at 03:07

0 Answers0