JavaScript Parse cloud signup, login using JS promises parse cloud sign up user

I'd like to create a parse.com cloud function that will either login or signup a user depending on if the credentials are recognized. I think I'm getting tripped up on promises, particularly on parameters to the then and error functions.

This function works:

function signUp(params) {
  var password = "my app supplies the password";
  var user = new Parse.User();

  user.set("username", params['email']);    // in my app, email==username
  user.set("password", password);
  user.set("email", params['email']);

  return user.signUp(null);
}

Calling it like this produces a good signUp result:

app.post('/reg', function(req, res) {
  signUp(req.body).then(function(user) {
    res.render('myView', { username: Parse.User.current().get('username') });
  }, function(user, error){
    res.render('myView', { username: 'error' });
  });
});

Similarly, this one works called in exactly the same way:

function logIn(params) {
  var username =  params['email'];
  var password = "my app supplies the password";
  return Parse.User.logIn(username, password);
}

Here's the problem, why doesn't this one work? called in the same way...

function logInOrSignUp(params) {
  logIn(params).then(function(user) {
    return user;
    // or should this be return Parse.Promise.as(user); ?
    // this is where I've become confused.
  }, function(user, error) {
    // login failed, let's take that to mean the user is new
    // issue: are these the right params for the error function?
    // the parse docs seem to indicate that login error block takes two params
    // issue: signUp(params) can return a promise, does this
    // return that promise from the function?
    return signUp(params);
  });
}

When I post to this with either an existing email address (username) or a novel one, I get "Server Error" back. (As an aside, I find myself clueless about how to debug. My dev loop is research-guess-code-deploy-inscrutableError-repeat...).

Answer:1

I have quite a bit more code than this so I'm trimming it down to just what seems to be relevant. Per the documented example, I have a python class for ZeroRPC to use: import zerorpc, sys, signal ...

I have quite a bit more code than this so I'm trimming it down to just what seems to be relevant. Per the documented example, I have a python class for ZeroRPC to use: import zerorpc, sys, signal ...

  1. zeromq python server
  2. python zeromq server example

Why can't you access the object property with dot notation inside a loop? var rockSpearguns = { Sharpshooter: {barbs: 2, weight: 10, heft: "overhand"}, Pokepistol: {barbs: 4, weight: 8, heft: "...

Why can't you access the object property with dot notation inside a loop? var rockSpearguns = { Sharpshooter: {barbs: 2, weight: 10, heft: "overhand"}, Pokepistol: {barbs: 4, weight: 8, heft: "...

  1. calling methods using objects in java
  2. calling methods on objects java

I'm learning AngularJS and I have a bit of a problem with directives. I don't like how they look. Specifically, I don't like when there is a lot of html in the middle of the javascript. Look at the ...

I'm learning AngularJS and I have a bit of a problem with directives. I don't like how they look. Specifically, I don't like when there is a lot of html in the middle of the javascript. Look at the ...

  1. angularjs directive without template
  2. angularjs directive without controller
  3. angularjs directive without isolated scope
  4. angularjs directive without scope
  5. angularjs directives not working
  6. angularjs directive not rendering
  7. angularjs directive not loading
  8. angularjs directive not showing
  9. angularjs directive not updating
  10. angularjs directive not being called
  11. angularjs directive not isolated scope
  12. angularjs directive not refreshing
  13. angularjs directive not updating parent scope
  14. angularjs directive not showing up
  15. angularjs directive not updating scope
  16. angularjs directive attribute without value

I'm trying to create a combobox to show moths, when I do click on january I only need to see div1 and febraury need to see div 2 like this: January........ <div> It will show info when ...

I'm trying to create a combobox to show moths, when I do click on january I only need to see div1 and febraury need to see div 2 like this: January........ <div> It will show info when ...

  1. javascript create and show div
  2. how to create a slideshow in javascript
  3. javascript createelement show
  4. create image slideshow in javascript