Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User setPassword cause Object not found #260

Closed
flessard opened this issue Feb 5, 2016 · 9 comments
Closed

User setPassword cause Object not found #260

flessard opened this issue Feb 5, 2016 · 9 comments
Labels
type:question Support or code-level question

Comments

@flessard
Copy link
Contributor

flessard commented Feb 5, 2016

If i try to change the password for a user, i always got Object not found error after save user object.
This is my code i user in cloud code function.

`
var query = new Parse.Query(Parse.User);
query.equalTo("email", request.params.email);

return query.first().then(function(user) {
    if (user && user.get('resetPasswordCode') === request.params.code) {
        user.set('resetPasswordCode', '');
        //if comment this line, work fine
        user.setPassword(request.params.password);
        return user.save();
    } else {
        return Parse.Promise.error(new FOLO.Error(FOLO.Error.RESET_PASSWORD_EMAIL_NOT_FOUND, "No account found with that email address."));
    }
}).then(function() {
    response.success(FOLO.Response());
}, function(error) {
    response.error(error);
});

`

@thibauddavid
Copy link

You need to call Parse.Cloud.useMasterKey() to update an user which is not logged in

@flessard
Copy link
Contributor Author

flessard commented Feb 5, 2016

Yes i call it. I just include a part of my code where don't include the header where i call Parse.Cloud.useMasterKey().

@gfosco
Copy link
Contributor

gfosco commented Feb 5, 2016

Try return user.save(null, { useMasterKey: true });

@flessard
Copy link
Contributor Author

flessard commented Feb 5, 2016

@gfosco nice, is working. Thanks for your help !

@flessard flessard closed this as completed Feb 5, 2016
@thibauddavid
Copy link

Why didn't Parse.Cloud.useMasterKey() worked in your case ?

@flessard
Copy link
Contributor Author

flessard commented Feb 6, 2016

yeah good question. Why @gfosco ?

@flessard flessard reopened this Feb 6, 2016
@drew-gross
Copy link
Contributor

useMasterKeyis a function that modifies global variables. On parse.com, this is fine, because a new JavaScript environment is created for every function call, but in a Node.js environment, global variables can affect other requests that are in progress. useMasterKey, along with Parse.User.current(), are just two things that fundamentally can't exist in a Node.js based version of Cloud Code.

@flessard
Copy link
Contributor Author

flessard commented Feb 6, 2016

Ok thanks @drew-gross !

@thibauddavid
Copy link

That should be explicitly told in Parse Migration Guide - 3. Cloud Code.
This could break many apps that are using Parse.Cloud.useMasterKey instead of {useMasterKey : true}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question Support or code-level question
Projects
None yet
Development

No branches or pull requests

5 participants