ResetPassword problems in meteor

I sent an email to the user and when he enters the password and other data, I try to reset the password, but it throws an error

uncaught error extpected to find a document to change

enter image description here

As you can see in the magician

I signed up for a user account

my code

this.route('enroll', {
        path: '/enroll-account/:token',
        template: 'enroll_page',
        onBeforeAction: function() {
            Meteor.logout();
            Session.set('_resetPasswordToken', this.params.token);
            s = this.subscribe('enrolledUser', this.params.token).wait();
        }
    }),

After the form and submission event are displayed

onSubmit: function(creds) {
            var options = {
                _id: Meteor.users.findOne()._id,
                name: creds.name
            }
            var token=Session.get('_resetPasswordToken');
            Meteor.call('updateUser', options, function(error, result) {
                if(!error) {
                    Accounts.resetPassword(token, creds.password, function(error) {
                        if (error) {
                            toastr.error("Sorry we could not update your password. Please try again.");
                            return false;
                        }
                        else{
                            toastr.error("Logged In");
                            Router.go('/');
                        }
                    });
                } else {
                    toastr.error("Sorry we could not update your password. Please try again.");
                    return false;
                }
            });
            this.resetForm();
            this.done();

            return false;
        }

Everything works fine, but the resetpassword callback does not start, and the above error is displayed in the console.

my token is removed from the user account, and I can log in using the login form, but

From the documents

Reset the password for a user using a token received in email. Logs the user in afterwards.

I can not automatically log in after resetting the password, throws errors above

What am I missing here?

+4
source share
2 answers
this.subscribe('enrolledUser', this.params.token).wait();

here you subscribe using the resetPassword token

Accounts.resetPassword, reset .

, , ( waht Expected to find a document to change)

, Id

path: '/enroll-account/:token',
        template: 'enroll_page',
        onBeforeAction: function() {
            Meteor.logout();
            Session.set('_resetPasswordToken', this.params.token);
            s = this.subscribe('enrolledUser', this.params.token).wait();
        },
        onAfterAction:function(){
               if(this.ready()){
                  var userid=Meteor.users.findOne()._id;
                  Meteor.subscribe("userRecord",userid);
               }
        }
+5

- . ( , ).

Meteor.publish('enrolledUser', function (token) {
  check(token, String);
  return Meteor.users.find({
    $or: [{
      _id: this.userId
    }, {
      'services.password.reset.token': token
    }]
  });
});

:

Reset , , . .

, , . , .

+1

Source: https://habr.com/ru/post/1568528/


All Articles